@syncular/console 0.0.6-55 → 0.0.6-56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/console",
3
- "version": "0.0.6-55",
3
+ "version": "0.0.6-56",
4
4
  "description": "Embeddable Syncular console UI",
5
5
  "license": "MIT",
6
6
  "author": "Benjamin Kniffler",
@@ -68,9 +68,9 @@
68
68
  "release": "bunx syncular-publish"
69
69
  },
70
70
  "dependencies": {
71
- "@syncular/observability-sentry": "0.0.6-55",
72
- "@syncular/transport-http": "0.0.6-55",
73
- "@syncular/ui": "0.0.6-55",
71
+ "@syncular/observability-sentry": "0.0.6-56",
72
+ "@syncular/transport-http": "0.0.6-56",
73
+ "@syncular/ui": "0.0.6-56",
74
74
  "@tanstack/react-query": "^5.90.21",
75
75
  "@tanstack/react-router": "^1.161.3",
76
76
  "lucide-react": "^0.575.0"
@@ -83,4 +83,4 @@ ${a}
83
83
  ${l.right}px ${l.bottom}px,
84
84
  ${l.right}px ${l.top}px,
85
85
  ${l.left}px ${l.top}px
86
- )`}return h.jsx("div",{ref:n,role:"presentation","data-base-ui-inert":"",...i,style:{position:"fixed",inset:0,userSelect:"none",WebkitUserSelect:"none",clipPath:a}})});function Qh(e,t){e&&Object.assign(e.style,t)}const OK={position:"relative",maxHeight:"100%",overflowX:"hidden",overflowY:"auto"},MK={position:"fixed"},IK=_.forwardRef(function(t,n){const{anchor:s,positionMethod:i="absolute",className:a,render:l,side:f="bottom",align:d="center",sideOffset:p=0,alignOffset:g=0,collisionBoundary:y="clipping-ancestors",collisionPadding:b,arrowPadding:x=5,sticky:S=!1,disableAnchorTracking:w,alignItemWithTrigger:T=!0,collisionAvoidance:C=Y9,...O}=t,{store:N,listRef:R,labelsRef:M,alignItemWithTriggerActiveRef:z,selectedItemTextRef:j,valuesRef:A,initialValueRef:P,popupRef:Q,setValue:B}=Wu(),U=$A(),Z=at(N,it.open),G=at(N,it.mounted),ee=at(N,it.modal),D=at(N,it.value),K=at(N,it.openMethod),q=at(N,it.positionerElement),V=at(N,it.triggerElement),L=at(N,it.isItemEqualToValue),I=at(N,it.transitionStatus),H=_.useRef(null),W=_.useRef(null),[Y,ae]=_.useState(T),se=G&&Y&&K!=="touch";!G&&Y!==T&&ae(T),Le(()=>{G||(it.scrollUpArrowVisible(N.state)&&N.set("scrollUpArrowVisible",!1),it.scrollDownArrowVisible(N.state)&&N.set("scrollDownArrowVisible",!1))},[N,G]),_.useImperativeHandle(z,()=>se),BA((se||ee)&&Z&&K!=="touch",V);const fe=DA({anchor:s,floatingRootContext:U,positionMethod:i,mounted:G,side:f,sideOffset:p,align:d,alignOffset:g,arrowPadding:x,collisionBoundary:y,collisionPadding:b,sticky:S,disableAnchorTracking:w??se,collisionAvoidance:C,keepMounted:!0}),Se=se?"none":fe.side,pe=se?MK:fe.positionerStyles,Me=_.useMemo(()=>{const xe={};return Z||(xe.pointerEvents="none"),{role:"presentation",hidden:!G,style:{...pe,...xe}}},[Z,G,pe]),_e={open:Z,side:Se,align:fe.align,anchorHidden:fe.anchorHidden},re=ke(xe=>{N.set("positionerElement",xe)}),he=zt("div",t,{ref:[n,re],state:_e,stateAttributesMapping:nl,props:[Me,Np(I),O]}),ie=_.useRef(0),we=ke(xe=>{if(xe.size===0&&ie.current===0||A.current.length===0)return;const ve=ie.current;if(ie.current=xe.size,xe.size===ve)return;const Ie=Yt(ii);if(ve!==0&&!N.state.multiple&&D!==null&&zy(A.current,D,L)===-1){const Ee=P.current,Qe=Ee!=null&&zy(A.current,Ee,L)!==-1?Ee:null;B(Qe,Ie),Qe===null&&(N.set("selectedIndex",null),j.current=null)}if(ve!==0&&N.state.multiple&&Array.isArray(D)){const Ue=Ve=>zy(A.current,Ve,L)!==-1,Ee=D.filter(Ve=>Ue(Ve));(Ee.length!==D.length||Ee.some(Ve=>!cK(D,Ve,L)))&&(B(Ee,Ie),Ee.length===0&&(N.set("selectedIndex",null),j.current=null))}if(Z&&se){N.update({scrollUpArrowVisible:!1,scrollDownArrowVisible:!1});const Ue={height:""};Qh(q,Ue),Qh(Q.current,Ue)}}),ye=_.useMemo(()=>({...fe,side:Se,alignItemWithTriggerActive:se,setControlledAlignItemWithTrigger:ae,scrollUpArrowRef:H,scrollDownArrowRef:W}),[fe,Se,se,ae]);return h.jsx(HA,{elementsRef:R,labelsRef:M,onMapChange:we,children:h.jsxs(qA.Provider,{value:ye,children:[G&&ee&&h.jsx(VA,{inert:fx(!Z),cutout:V}),he]})})});function GA(e){const t=e.currentTarget.getBoundingClientRect();return t.top+1<=e.clientY&&e.clientY<=t.bottom-1&&t.left+1<=e.clientX&&e.clientX<=t.right-1}const Vd="base-ui-disable-scrollbar",PC={className:Vd,getElement(e){return h.jsx("style",{nonce:e,href:Vd,precedence:"base-ui:low",children:`.${Vd}{scrollbar-width:none}.${Vd}::-webkit-scrollbar{display:none}`})}},PK=_.createContext(void 0);function KA(e){return _.useContext(PK)}const wc="ArrowUp",Wi="ArrowDown",Ru="ArrowLeft",Ec="ArrowRight",Ju="Home",ef="End",ZA=new Set([Ru,Ec]),DK=new Set([Ru,Ec,Ju,ef]),YA=new Set([wc,Wi]),zK=new Set([wc,Wi,Ju,ef]),XA=new Set([...ZA,...YA]),LK=new Set([...XA,Ju,ef]),QA=new Set([wc,Wi,Ru,Ec,Ju,ef]),UK="Shift",$K="Control",BK="Alt",FK="Meta",HK=new Set([UK,$K,BK,FK]);function qK(e){return Zt(e)&&e.tagName==="INPUT"}function DC(e){return!!(qK(e)&&e.selectionStart!=null||Zt(e)&&e.tagName==="TEXTAREA")}function zC(e,t,n,s){if(!e||!t||!t.scrollTo)return;let i=e.scrollLeft,a=e.scrollTop;const l=e.clientWidth<e.scrollWidth,f=e.clientHeight<e.scrollHeight;if(l&&s!=="vertical"){const d=LC(e,t,"left"),p=Gd(e),g=Gd(t);n==="ltr"&&(d+t.offsetWidth+g.scrollMarginRight>e.scrollLeft+e.clientWidth-p.scrollPaddingRight?i=d+t.offsetWidth+g.scrollMarginRight-e.clientWidth+p.scrollPaddingRight:d-g.scrollMarginLeft<e.scrollLeft+p.scrollPaddingLeft&&(i=d-g.scrollMarginLeft-p.scrollPaddingLeft)),n==="rtl"&&(d-g.scrollMarginRight<e.scrollLeft+p.scrollPaddingLeft?i=d-g.scrollMarginLeft-p.scrollPaddingLeft:d+t.offsetWidth+g.scrollMarginRight>e.scrollLeft+e.clientWidth-p.scrollPaddingRight&&(i=d+t.offsetWidth+g.scrollMarginRight-e.clientWidth+p.scrollPaddingRight))}if(f&&s!=="horizontal"){const d=LC(e,t,"top"),p=Gd(e),g=Gd(t);d-g.scrollMarginTop<e.scrollTop+p.scrollPaddingTop?a=d-g.scrollMarginTop-p.scrollPaddingTop:d+t.offsetHeight+g.scrollMarginBottom>e.scrollTop+e.clientHeight-p.scrollPaddingBottom&&(a=d+t.offsetHeight+g.scrollMarginBottom-e.clientHeight+p.scrollPaddingBottom)}e.scrollTo({left:i,top:a,behavior:"auto"})}function LC(e,t,n){const s=n==="left"?"offsetLeft":"offsetTop";let i=0;for(;t.offsetParent&&(i+=t[s],t.offsetParent!==e);)t=t.offsetParent;return i}function Gd(e){const t=getComputedStyle(e);return{scrollMarginTop:parseFloat(t.scrollMarginTop)||0,scrollMarginRight:parseFloat(t.scrollMarginRight)||0,scrollMarginBottom:parseFloat(t.scrollMarginBottom)||0,scrollMarginLeft:parseFloat(t.scrollMarginLeft)||0,scrollPaddingTop:parseFloat(t.scrollPaddingTop)||0,scrollPaddingRight:parseFloat(t.scrollPaddingRight)||0,scrollPaddingBottom:parseFloat(t.scrollPaddingBottom)||0,scrollPaddingLeft:parseFloat(t.scrollPaddingLeft)||0}}function Ly(e,t=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,n))}const VK=_.createContext(void 0),GK={disableStyleElements:!1};function KK(){return _.useContext(VK)??GK}const Vi=1,ZK={...nl,...ba},YK=_.forwardRef(function(t,n){const{render:s,className:i,finalFocus:a,...l}=t,{store:f,popupRef:d,onOpenChangeComplete:p,setOpen:g,valueRef:y,selectedItemTextRef:b,keyboardActiveRef:x,multiple:S,handleScrollArrowVisibility:w,scrollHandlerRef:T,highlightItemOnHover:C}=Wu(),{side:O,align:N,alignItemWithTriggerActive:R,setControlledAlignItemWithTrigger:M,scrollDownArrowRef:z,scrollUpArrowRef:j}=kK(),A=KA()!=null,P=$A(),{nonce:Q,disableStyleElements:B}=KK(),U=ns(),Z=at(f,it.id),G=at(f,it.open),ee=at(f,it.mounted),D=at(f,it.popupProps),K=at(f,it.transitionStatus),q=at(f,it.triggerElement),V=at(f,it.positionerElement),L=at(f,it.listElement),I=_.useRef(0),H=_.useRef(!1),W=_.useRef(0),Y=_.useRef(!1),ae=_.useRef({}),se=ox(),fe=ke(_e=>{if(!V||!d.current||!Y.current)return;if(H.current||!R){w();return}const re=V.style.top==="0px",he=V.style.bottom==="0px",ie=V.getBoundingClientRect().height,we=Rt(V),ye=getComputedStyle(V),xe=parseFloat(ye.marginTop),ve=parseFloat(ye.marginBottom),Ie=UC(getComputedStyle(d.current)),Ue=Math.min(we.documentElement.clientHeight-xe-ve,Ie),Ee=_e.scrollTop,Ve=$C(_e);let Qe=0,Be=null,We=!1,He=!1;const me=qe=>{V.style.height=`${qe}px`},Te=(qe,ht)=>{const lt=Ly(qe,0,Ue-ie);lt>0&&me(ie+lt),_e.scrollTop=ht,Ue-(ie+lt)<=Vi&&(H.current=!0),w()};if(re){const qe=Ve-Ee,ht=ie+qe,lt=Math.min(ht,Ue);if(Qe=lt,qe<=Vi){Te(qe,Ve);return}Ue-lt>Vi?He=!0:We=!0}else if(he){const qe=Ee,ht=ie+qe,lt=Math.min(ht,Ue),wr=ht-Ue;if(Qe=lt,qe<=Vi){Te(qe,0);return}Ue-lt>Vi?Be=0:(We=!0,Ee<Ve&&(Be=Ee-(qe-wr)))}if(Qe=Math.ceil(Qe),Qe!==0&&me(Qe),He||Be!=null){const qe=$C(_e),ht=He?qe:Ly(Be,0,qe);Math.abs(_e.scrollTop-ht)>Vi&&(_e.scrollTop=ht)}(We||Qe>=Ue-Vi)&&(H.current=!0),w()});_.useImperativeHandle(T,()=>fe,[fe]),xa({open:G,ref:d,onComplete(){G&&p?.(!0)}});const Se={open:G,transitionStatus:K,side:O,align:N};Le(()=>{!V||!d.current||Object.keys(ae.current).length||(ae.current={top:V.style.top||"0",left:V.style.left||"0",right:V.style.right,height:V.style.height,bottom:V.style.bottom,minHeight:V.style.minHeight,maxHeight:V.style.maxHeight,marginTop:V.style.marginTop,marginBottom:V.style.marginBottom})},[d,V]),Le(()=>{G||R||(Y.current=!1,H.current=!1,I.current=0,W.current=0,Qh(V,ae.current))},[G,R,V,d]),Le(()=>{const _e=d.current;if(!(!G||!q||!V||!_e||f.state.transitionStatus==="ending")){if(!R){Y.current=!0,se.request(w),_e.style.removeProperty("--transform-origin");return}queueMicrotask(()=>{const re=XK(_e);_e.style.removeProperty("--transform-origin");try{const he=getComputedStyle(V),ie=getComputedStyle(_e),we=Rt(q),ye=un(V),xe=q.getBoundingClientRect(),ve=V.getBoundingClientRect(),Ie=xe.left,Ue=xe.height,Ee=L||_e,Ve=Ee.scrollHeight,Qe=parseFloat(ie.borderBottomWidth),Be=parseFloat(he.marginTop)||10,We=parseFloat(he.marginBottom)||10,He=parseFloat(he.minHeight)||100,me=UC(ie),Te=5,qe=5,ht=20,lt=we.documentElement.clientHeight-Be-We,wr=we.documentElement.clientWidth,Er=lt-xe.bottom+Ue,Qt=b.current,ut=y.current;let xt,ot=0,Wt=0;if(Qt&&ut){const tr=ut.getBoundingClientRect();xt=Qt.getBoundingClientRect();const cs=tr.left-Ie,fo=xt.left-ve.left,ho=tr.top-xe.top+tr.height/2,nr=xt.top-ve.top+xt.height/2;ot=cs-fo,Wt=nr-ho}const vn=Er+Wt+We+Qe;let kt=Math.min(lt,vn);const Cn=lt-Be-We,er=vn-kt,An=Math.max(Te,Ie+ot),is=wr-qe,as=Math.max(0,An+ve.width-is);V.style.left=`${An-as}px`,V.style.height=`${kt}px`,V.style.maxHeight="auto",V.style.marginTop=`${Be}px`,V.style.marginBottom=`${We}px`,_e.style.height="100%";const _a=Ee.scrollHeight-Ee.clientHeight,wi=er>=_a;wi&&(kt=Math.min(lt,ve.height)-(er-_a));const Ei=xe.top<ht||xe.bottom>lt-ht||kt<Math.min(Ve,He),_s=(ye.visualViewport?.scale??1)!==1&&tx;if(Ei||_s){Y.current=!0,Qh(V,ae.current),hi.flushSync(()=>M(!1));return}if(wi){const tr=Math.max(0,lt-vn);V.style.top=ve.height>=Cn?"0":`${tr}px`,V.style.height=`${kt}px`,Ee.scrollTop=Ee.scrollHeight-Ee.clientHeight,I.current=Math.max(He,kt)}else V.style.bottom="0",I.current=Math.max(He,kt),Ee.scrollTop=er;if(xt){const tr=ve.top,cs=ve.height,fo=xt.top+xt.height/2,ho=cs>0?(fo-tr)/cs*100:50,nr=Ly(ho,0,100);_e.style.setProperty("--transform-origin",`50% ${nr}%`)}(I.current===lt||kt>=me)&&(H.current=!0),w(),setTimeout(()=>{Y.current=!0})}finally{re()}})}},[f,G,V,q,y,b,d,w,R,M,se,z,j,L]),_.useEffect(()=>{if(!R||!V||!G)return;const _e=un(V);function re(he){g(!1,Yt(x8,he))}return _e.addEventListener("resize",re),()=>{_e.removeEventListener("resize",re)}},[g,R,V,G]);const pe={...L?{role:"presentation","aria-orientation":void 0}:{role:"listbox","aria-multiselectable":S||void 0,id:`${Z}-list`},onKeyDown(_e){x.current=!0,A&&QA.has(_e.key)&&_e.stopPropagation()},onMouseMove(){x.current=!1},onPointerLeave(_e){if(!C||GA(_e)||_e.pointerType==="touch")return;const re=_e.currentTarget;U.start(0,()=>{f.set("activeIndex",null),re.focus({preventScroll:!0})})},onScroll(_e){L||fe(_e.currentTarget)},...R&&{style:L?{height:"100%"}:OK}},Me=zt("div",t,{ref:[n,d],state:Se,stateAttributesMapping:ZK,props:[D,pe,Np(K),{className:!L&&R?PC.className:void 0},l]});return h.jsxs(_.Fragment,{children:[!B&&PC.getElement(Q),h.jsx(_A,{context:P,modal:!1,disabled:!ee,returnFocus:a,restoreFocus:!0,children:Me})]})});function UC(e){const t=e.maxHeight||"";return t.endsWith("px")&&parseFloat(t)||1/0}function $C(e){return Math.max(0,e.scrollHeight-e.clientHeight)}const BC=[["transform","none"],["scale","1"],["translate","0 0"]];function XK(e){const{style:t}=e,n={};for(const[s,i]of BC)n[s]=t.getPropertyValue(s),t.setProperty(s,i,"important");return()=>{for(const[s]of BC){const i=n[s];i?t.setProperty(s,i):t.removeProperty(s)}}}let WA=(function(e){return e[e.None=0]="None",e[e.GuessFromOrder=1]="GuessFromOrder",e})({});function dx(e={}){const{label:t,metadata:n,textRef:s,indexGuessBehavior:i,index:a}=e,{register:l,unregister:f,subscribeMapChange:d,elementsRef:p,labelsRef:g,nextIndexRef:y}=RK(),b=_.useRef(-1),[x,S]=_.useState(a??(i===WA.GuessFromOrder?()=>{if(b.current===-1){const C=y.current;y.current+=1,b.current=C}return b.current}:-1)),w=_.useRef(null),T=_.useCallback(C=>{if(w.current=C,x!==-1&&C!==null&&(p.current[x]=C,g)){const O=t!==void 0;g.current[x]=O?t:s?.current?.textContent??C.textContent}},[x,p,g,t,s]);return Le(()=>{if(a!=null)return;const C=w.current;if(C)return l(C,n),()=>{f(C)}},[a,l,f,n]),Le(()=>{if(a==null)return d(C=>{const O=w.current?C.get(w.current)?.index:null;O!=null&&S(O)})},[a,d,S]),_.useMemo(()=>({ref:T,index:x}),[x,T])}const QK=_.createContext(void 0),WK=_.memo(_.forwardRef(function(t,n){const{render:s,className:i,value:a=null,label:l,disabled:f=!1,nativeButton:d=!1,...p}=t,g=_.useRef(null),y=dx({label:l,textRef:g,indexGuessBehavior:WA.GuessFromOrder}),{store:b,getItemProps:x,setOpen:S,setValue:w,selectionRef:T,typingRef:C,valuesRef:O,keyboardActiveRef:N,multiple:R,highlightItemOnHover:M}=Wu(),z=ns(),j=at(b,it.isActive,y.index),A=at(b,it.isSelected,y.index,a),P=at(b,it.isSelectedByFocus,y.index),Q=at(b,it.isItemEqualToValue),B=y.index,U=B!==-1,Z=_.useRef(null),G=Jo(B);Le(()=>{if(!U)return;const se=O.current;return se[B]=a,()=>{delete se[B]}},[U,B,a,O]),Le(()=>{if(!U)return;const se=b.state.value;let fe=se;R&&Array.isArray(se)&&se.length>0&&(fe=se[se.length-1]),fe!==void 0&&$c(a,fe,Q)&&b.set("selectedIndex",B)},[U,B,R,Q,b,a]);const ee={disabled:f,selected:A,highlighted:j},D=x({active:j,selected:A});D.onFocus=void 0,D.id=void 0;const K=_.useRef(null),q=_.useRef("mouse"),V=_.useRef(!1),{getButtonProps:L,buttonRef:I}=Jc({disabled:f,focusableWhenDisabled:!0,native:d});function H(se){const fe=b.state.value;if(R){const Se=Array.isArray(fe)?fe:[],pe=A?lK(Se,a,Q):[...Se,a];w(pe,Yt(Cy,se))}else w(a,Yt(Cy,se)),S(!1,Yt(Cy,se))}const W={role:"option","aria-selected":A,tabIndex:j?0:-1,onFocus(){b.set("activeIndex",B)},onMouseEnter(){!N.current&&b.state.selectedIndex===null&&M&&b.set("activeIndex",B)},onMouseMove(){M&&b.set("activeIndex",B)},onMouseLeave(se){!M||N.current||GA(se)||z.start(0,()=>{b.state.activeIndex===B&&b.set("activeIndex",null)})},onTouchStart(){T.current={allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1}},onKeyDown(se){K.current=se.key,b.set("activeIndex",B)},onClick(se){V.current=!1,!(se.type==="keydown"&&K.current===null)&&(f||K.current===" "&&C.current||q.current!=="touch"&&!j||(K.current=null,H(se.nativeEvent)))},onPointerEnter(se){q.current=se.pointerType},onPointerDown(se){q.current=se.pointerType,V.current=!0},onMouseUp(se){if(f)return;if(V.current){V.current=!1;return}const fe=!T.current.allowSelectedMouseUp&&A,Se=!T.current.allowUnselectedMouseUp&&!A;fe||Se||q.current!=="touch"&&!j||H(se.nativeEvent)}},Y=zt("div",t,{ref:[I,n,y.ref,Z],state:ee,props:[D,W,p,L]}),ae=_.useMemo(()=>({selected:A,indexRef:G,textRef:g,selectedByFocus:P,hasRegistered:U}),[A,G,g,P,U]);return h.jsx(QK.Provider,{value:ae,children:Y})})),JK=_.forwardRef(({className:e,children:t,...n},s)=>h.jsx(vK,{ref:s,className:ge("inline-flex items-center justify-between bg-surface border border-border rounded-md px-3 py-1.5 font-mono text-[12px] text-foreground cursor-pointer hover:border-border-bright transition",e),...n,children:t}));JK.displayName="SelectTrigger";const eZ=_.forwardRef(({className:e,portalProps:t,positionerProps:n,...s},i)=>h.jsx(xK,{...t,children:h.jsx(IK,{...n,children:h.jsx(YK,{ref:i,className:ge("bg-panel border border-border rounded-md py-1 shadow-lg z-50",e),...s})})}));eZ.displayName="SelectContent";const tZ=_.forwardRef(({className:e,...t},n)=>h.jsx(WK,{ref:n,className:ge("font-mono text-[11px] px-3 py-1.5 text-neutral-400 cursor-pointer hover:bg-white/[0.03] hover:text-white data-[highlighted]:bg-white/[0.03] data-[highlighted]:text-white outline-none",e),...t}));tZ.displayName="SelectItem";const nZ=_.forwardRef(({className:e,...t},n)=>h.jsx("textarea",{ref:n,className:ge("bg-surface border border-border rounded-md px-3 py-2 font-mono text-[12px] text-foreground outline-none w-full transition focus:border-flow placeholder:text-neutral-600 resize-none min-h-[80px]",e),...t}));nZ.displayName="Textarea";const JA=_.createContext(void 0);function rZ(e=!0){const t=_.useContext(JA);if(t===void 0&&!e)throw new Error(yn(7));return t}function ek(e={}){const{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:s}=jj(),{ref:i,index:a}=dx(e),l=n===a,f=_.useRef(null),d=so(i,f);return{compositeProps:_.useMemo(()=>({tabIndex:l?0:-1,onFocus(){s(a)},onMouseMove(){const g=f.current;if(!t||!g)return;const y=g.hasAttribute("disabled")||g.ariaDisabled==="true";!l&&!y&&g.focus()}}),[l,s,a,t]),compositeRef:d,index:a}}function sZ(e){const{render:t,className:n,state:s=an,props:i=Eu,refs:a=Eu,metadata:l,stateAttributesMapping:f,tag:d="div",...p}=e,{compositeProps:g,compositeRef:y}=ek({metadata:l});return zt(d,e,{state:s,ref:[...a,y],props:[g,...i,p],stateAttributesMapping:f})}const oZ=_.forwardRef(function(t,n){const{className:s,defaultPressed:i=!1,disabled:a=!1,form:l,onPressedChange:f,pressed:d,render:p,type:g,value:y,nativeButton:b=!0,...x}=t,S=br(y||void 0),w=rZ(),T=w?.value??[],C=w?void 0:i,O=(a||w?.disabled)??!1,[N,R]=pp({controlled:w?S!==void 0&&T.indexOf(S)>-1:d,default:C,name:"Toggle",state:"pressed"}),M=ke((U,Z)=>{S&&w?.setGroupValue?.(S,U,Z),f?.(U,Z)}),{getButtonProps:z,buttonRef:j}=Jc({disabled:O,native:b}),A={disabled:O,pressed:N},P=[j,n],Q=[{"aria-pressed":N,onClick(U){const Z=!N,G=Yt(ii,U.nativeEvent);M(Z,G),!G.isCanceled&&R(Z)}},x,z],B=zt("button",t,{enabled:!w,state:A,ref:P,props:Q});return w?h.jsx(sZ,{tag:"button",render:p,className:s,state:A,refs:P,props:Q}):B}),Dr=_.forwardRef(({className:e,...t},n)=>h.jsx(oZ,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 border border-transparent rounded-sm px-2.5 py-1 cursor-pointer transition-all hover:text-neutral-300 data-[pressed]:text-white data-[pressed]:border-border-bright data-[pressed]:bg-white/[0.03]",e),...t}));Dr.displayName="Toggle";function iZ(e){return e==null||e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}const tk="data-composite-item-active",aZ=[];function cZ(e){const{itemSizes:t,cols:n=1,loopFocus:s=!0,dense:i=!1,orientation:a="both",direction:l,highlightedIndex:f,onHighlightedIndexChange:d,rootRef:p,enableHomeAndEndKeys:g=!1,stopEventPropagation:y=!1,disabledIndices:b,modifierKeys:x=aZ}=e,[S,w]=_.useState(0),T=n>1,C=_.useRef(null),O=so(C,p),N=_.useRef([]),R=_.useRef(!1),M=f??S,z=ke((P,Q=!1)=>{if((d??w)(P),Q){const B=N.current[P];zC(C.current,B,l,a)}}),j=ke(P=>{if(P.size===0||R.current)return;R.current=!0;const Q=Array.from(P.keys()),B=Q.find(Z=>Z?.hasAttribute(tk))??null,U=B?Q.indexOf(B):-1;U!==-1&&z(U),zC(C.current,B,l,a)}),A=_.useMemo(()=>({"aria-orientation":a==="both"?void 0:a,ref:O,onFocus(P){!C.current||!DC(P.target)||P.target.setSelectionRange(0,P.target.value.length??0)},onKeyDown(P){const Q=g?LK:XA;if(!Q.has(P.key)||lZ(P,x)||!C.current)return;const U=l==="rtl",Z=U?Ru:Ec,G={horizontal:Z,vertical:Wi,both:Z}[a],ee=U?Ec:Ru,D={horizontal:ee,vertical:wc,both:ee}[a];if(DC(P.target)&&!iZ(P.target)){const W=P.target.selectionStart,Y=P.target.selectionEnd,ae=P.target.value??"";if(W==null||P.shiftKey||W!==Y||P.key!==D&&W<ae.length||P.key!==G&&W>0)return}let K=M;const q=wV(N,b),V=EV(N,b);if(T){const W=t||Array.from({length:N.current.length},()=>({width:1,height:1})),Y=CV(W,n,i),ae=Y.findIndex(fe=>fe!=null&&!fu(N,fe,b)),se=Y.reduce((fe,Se,pe)=>Se!=null&&!fu(N,Se,b)?pe:fe,-1);K=Y[TV({current:Y.map(fe=>fe?N.current[fe]:null)},{event:P,orientation:a,loopFocus:s,cols:n,disabledIndices:NV([...b||N.current.map((fe,Se)=>fu(N,Se)?Se:void 0),void 0],Y),minIndex:ae,maxIndex:se,prevIndex:RV(M>V?q:M,W,Y,n,P.key===Wi?"bl":P.key===Ec?"tr":"tl"),rtl:U})]}const L={horizontal:[Z],vertical:[Wi],both:[Z,Wi]}[a],I={horizontal:[ee],vertical:[wc],both:[ee,wc]}[a],H=T?Q:{horizontal:g?DK:ZA,vertical:g?zK:YA,both:Q}[a];g&&(P.key===Ju?K=q:P.key===ef&&(K=V)),K===M&&(L.includes(P.key)||I.includes(P.key))&&(s&&K===V&&L.includes(P.key)?K=q:s&&K===q&&I.includes(P.key)?K=V:K=fr(N,{startingIndex:K,decrement:I.includes(P.key),disabledIndices:b})),K!==M&&!ch(N,K)&&(y&&P.stopPropagation(),H.has(P.key)&&P.preventDefault(),z(K,!0),queueMicrotask(()=>{N.current[K]?.focus()}))}}),[n,i,l,b,N,g,M,T,t,s,O,x,z,a,y]);return _.useMemo(()=>({props:A,highlightedIndex:M,onHighlightedIndexChange:z,elementsRef:N,disabledIndices:b,onMapChange:j,relayKeyboardEvent:A.onKeyDown}),[A,M,z,N,b,j])}function lZ(e,t){for(const n of HK.values())if(!t.includes(n)&&e.getModifierState(n))return!0;return!1}function nk(e){const{render:t,className:n,refs:s=Eu,props:i=Eu,state:a=an,stateAttributesMapping:l,highlightedIndex:f,onHighlightedIndexChange:d,orientation:p,dense:g,itemSizes:y,loopFocus:b,cols:x,enableHomeAndEndKeys:S,onMapChange:w,stopEventPropagation:T=!0,rootRef:C,disabledIndices:O,modifierKeys:N,highlightItemOnHover:R=!1,tag:M="div",...z}=e,j=IA(),{props:A,highlightedIndex:P,onHighlightedIndexChange:Q,elementsRef:B,onMapChange:U,relayKeyboardEvent:Z}=cZ({itemSizes:y,cols:x,loopFocus:b,dense:g,orientation:p,highlightedIndex:f,onHighlightedIndexChange:d,rootRef:C,stopEventPropagation:T,enableHomeAndEndKeys:S,direction:j,disabledIndices:O,modifierKeys:N}),G=zt(M,e,{state:a,ref:s,props:[A,...i,z],stateAttributesMapping:l}),ee=_.useMemo(()=>({highlightedIndex:P,onHighlightedIndexChange:Q,highlightItemOnHover:R,relayKeyboardEvent:Z}),[P,Q,R,Z]);return h.jsx(Nj.Provider,{value:ee,children:h.jsx(HA,{elementsRef:B,onMapChange:D=>{w?.(D),U(D)},children:G})})}let uZ=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e.multiple="data-multiple",e})({});const FC={multiple(e){return e?{[uZ.multiple]:""}:null}},fZ=_.forwardRef(function(t,n){const{defaultValue:s,disabled:i=!1,loopFocus:a=!0,onValueChange:l,orientation:f="horizontal",multiple:d=!1,value:p,className:g,render:y,...b}=t,x=KA(),S=_.useMemo(()=>{if(p===void 0)return s??[]},[p,s]),w=_.useMemo(()=>p!==void 0||s!==void 0,[p,s]),T=(x?.disabled??!1)||i,[C,O]=pp({controlled:p,default:S,name:"ToggleGroup",state:"value"}),N=ke((A,P,Q)=>{let B;if(d?(B=C.slice(),P?B.push(A):B.splice(C.indexOf(A),1)):B=P?[A]:[],Array.isArray(B)){if(l?.(B,Q),Q.isCanceled)return;O(B)}}),R={disabled:T,multiple:d,orientation:f},M=_.useMemo(()=>({disabled:T,orientation:f,setGroupValue:N,value:C,isValueInitialized:w}),[T,f,N,C,w]),z={role:"group"},j=zt("div",t,{enabled:!!x,state:R,ref:n,props:[z,b],stateAttributesMapping:FC});return h.jsx(JA.Provider,{value:M,children:x?j:h.jsx(nk,{render:y,className:g,state:R,refs:[n],props:[z,b],stateAttributesMapping:FC,loopFocus:a,enableHomeAndEndKeys:!0})})}),dh=_.forwardRef(({className:e,...t},n)=>h.jsx(fZ,{ref:n,className:ge("flex items-center gap-0.5",e),...t}));dh.displayName="ToggleGroup";const dZ=ge($j({variant:"secondary",size:"sm"}),"h-7 whitespace-nowrap uppercase tracking-[0.08em] leading-none no-underline");function rk({active:e,onClick:t,children:n,className:s}){return h.jsxs("button",{type:"button",onClick:t,className:ge("font-mono text-[10px] tracking-[1.5px] uppercase bg-transparent border-none px-3.5 py-1 cursor-pointer relative transition-colors",e?"text-white":"text-neutral-500 hover:text-neutral-300",s),children:[n,e&&h.jsx("span",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 w-4 h-0.5 bg-flow rounded-sm shadow-[0_0_8px_rgba(59,130,246,0.5)]"})]})}function hZ({items:e,activeId:t,onItemChange:n,renderItem:s,className:i}){return h.jsx("div",{className:ge("flex items-center gap-0.5",i),children:e.map(a=>{const l=a.id===t,f=()=>n?.(a.id);return s?h.jsx("span",{children:s(a,{active:l,onClick:f})},a.id):h.jsx(rk,{active:l,onClick:f,children:a.label},a.id)})})}const pZ=gi("rounded-full inline-block flex-shrink-0",{variants:{color:{healthy:"bg-healthy",syncing:"bg-syncing",offline:"bg-offline",flow:"bg-flow",relay:"bg-relay",encrypt:"bg-encrypt",muted:"bg-neutral-500"},size:{sm:"w-1.5 h-1.5",md:"w-2 h-2",lg:"w-2.5 h-2.5"},glow:{true:"",false:""}},defaultVariants:{color:"healthy",size:"sm",glow:!1}}),mZ={healthy:"0 0 6px #22c55e",syncing:"0 0 6px #f59e0b",offline:"0 0 6px #ef4444",flow:"0 0 6px #3b82f6",relay:"0 0 6px #8b5cf6",encrypt:"0 0 6px #f472b6",muted:"none"};function gZ({color:e,size:t,glow:n,pulse:s,className:i}){return h.jsx("span",{className:ge(pZ({color:e,size:t,glow:n}),s&&"dot-pulse",i),style:n?{boxShadow:mZ[e??"healthy"]}:void 0})}const yZ="0.0.6-55",vZ={version:yZ},bZ=vZ.version;function xZ({label:e,className:t}){return h.jsxs("div",{className:ge("flex items-center gap-3",t),children:[h.jsx(gZ,{color:"healthy",size:"md",glow:!0}),h.jsx("span",{className:"font-display font-bold text-white text-sm tracking-tight",children:"syncular"}),e&&h.jsx("span",{className:"font-mono text-[9px] text-neutral-600 uppercase tracking-widest",children:e}),h.jsxs("span",{className:"font-mono text-[9px] text-neutral-600 tracking-wider",children:["v",bZ]})]})}function SZ({brand:e,center:t,right:n,className:s}){return h.jsxs(h.Fragment,{children:[h.jsx("div",{"aria-hidden":"true",className:"h-[42px] shrink-0"}),h.jsxs("nav",{className:ge("fixed top-0 left-0 right-0 z-100 h-[42px] border-b border-border bg-surface/88 backdrop-blur-lg flex items-center justify-between px-5",s),children:[h.jsx("div",{className:"flex items-center gap-3",children:e}),h.jsx("div",{className:"flex items-center gap-0.5",children:t}),h.jsx("div",{className:"flex items-center gap-2",children:n})]})]})}const _Z=gi("border rounded-lg p-3 font-mono text-[11px]",{variants:{variant:{default:"border-border bg-panel",destructive:"border-offline/20 bg-offline/5 text-offline"}},defaultVariants:{variant:"default"}}),In=_.forwardRef(({className:e,variant:t,...n},s)=>h.jsx("div",{ref:s,role:"alert",className:ge(_Z({variant:t,className:e})),...n}));In.displayName="Alert";const tf=_.forwardRef(({className:e,...t},n)=>h.jsx("h5",{ref:n,className:ge("font-medium text-white mb-1",e),...t}));tf.displayName="AlertTitle";const Pn=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("text-neutral-400",e),...t}));Pn.displayName="AlertDescription";const sk=_.createContext(void 0);function rl(e){const t=_.useContext(sk);if(e===!1&&t===void 0)throw new Error(yn(27));return t}const wZ={...nl,...ba},hx=_.forwardRef(function(t,n){const{render:s,className:i,forceRender:a=!1,...l}=t,{store:f}=rl(),d=f.useState("open"),p=f.useState("nested"),g=f.useState("mounted"),y=f.useState("transitionStatus");return zt("div",t,{state:{open:d,transitionStatus:y},ref:[f.context.backdropRef,n],stateAttributesMapping:wZ,props:[{role:"presentation",hidden:!g,style:{userSelect:"none",WebkitUserSelect:"none"}},l],enabled:a||!p})}),ok=_.forwardRef(function(t,n){const{render:s,className:i,id:a,...l}=t,{store:f}=rl(),d=br(a);return f.useSyncedValueWithCleanup("descriptionElementId",d),zt("p",t,{ref:n,props:[{id:d},l]})});let EZ=(function(e){return e.nestedDialogs="--nested-dialogs",e})({}),TZ=(function(e){return e[e.open=Qi.open]="open",e[e.closed=Qi.closed]="closed",e[e.startingStyle=Qi.startingStyle]="startingStyle",e[e.endingStyle=Qi.endingStyle]="endingStyle",e.nested="data-nested",e.nestedDialogOpen="data-nested-dialog-open",e})({});const ik=_.createContext(void 0);function CZ(){const e=_.useContext(ik);if(e===void 0)throw new Error(yn(26));return e}const RZ={...nl,...ba,nestedDialogOpen(e){return e?{[TZ.nestedDialogOpen]:""}:null}},ak=_.forwardRef(function(t,n){const{className:s,finalFocus:i,initialFocus:a,render:l,...f}=t,{store:d}=rl(),p=d.useState("descriptionElementId"),g=d.useState("disablePointerDismissal"),y=d.useState("floatingRootContext"),b=d.useState("popupProps"),x=d.useState("modal"),S=d.useState("mounted"),w=d.useState("nested"),T=d.useState("nestedOpenDialogCount"),C=d.useState("open"),O=d.useState("openMethod"),N=d.useState("titleElementId"),R=d.useState("transitionStatus"),M=d.useState("role");CZ(),xa({open:C,ref:d.context.popupRef,onComplete(){C&&d.context.onOpenChangeComplete?.(!0)}});function z(B){return B==="touch"?d.context.popupRef.current:!0}const j=a===void 0?z:a,A=T>0,Q=zt("div",t,{state:{open:C,nested:w,transitionStatus:R,nestedDialogOpen:A},props:[b,{"aria-labelledby":N??void 0,"aria-describedby":p??void 0,role:M,tabIndex:-1,hidden:!S,onKeyDown(B){QA.has(B.key)&&B.stopPropagation()},style:{[EZ.nestedDialogs]:T}},f],ref:[n,d.context.popupRef,d.useStateSetter("popupElement")],stateAttributesMapping:RZ});return h.jsx(_A,{context:y,openInteractionType:O,disabled:!S,closeOnFocusOut:!g,initialFocus:j,returnFocus:i,modal:x!==!1,restoreFocus:"popup",children:Q})}),ck=_.forwardRef(function(t,n){const{keepMounted:s=!1,...i}=t,{store:a}=rl(),l=a.useState("mounted"),f=a.useState("modal"),d=a.useState("open");return l||s?h.jsx(ik.Provider,{value:s,children:h.jsxs(SA,{ref:n,...i,children:[l&&f===!0&&h.jsx(VA,{ref:a.context.internalBackdropRef,inert:fx(!d)}),t.children]})}):null});function NZ(e){const{store:t,parentContext:n,actionsRef:s}=e,i=t.useState("open"),a=t.useState("disablePointerDismissal"),l=t.useState("modal"),f=t.useState("popupElement"),{openMethod:d,triggerProps:p,reset:g}=pK(i);sG(t);const{forceUnmount:y}=oG(i,t,()=>{g()}),b=ke(Q=>{const B=Yt(Q);return B.preventUnmountOnClose=()=>{t.set("preventUnmountingOnClose",!0)},B}),x=_.useCallback(()=>{t.setOpen(!1,b(b8))},[t,b]);_.useImperativeHandle(s,()=>({unmount:y,close:x}),[y,x]);const S=fG({popupStore:t,onOpenChange:t.setOpen,treatPopupAsFloatingElement:!0,noEmit:!0}),[w,T]=_.useState(0),C=w===0,O=xG(S),N=G7(S,{outsidePressEvent(){return t.context.internalBackdropRef.current||t.context.backdropRef.current?"intentional":{mouse:l==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}},outsidePress(Q){if(!t.context.outsidePressEnabledRef.current||"button"in Q&&Q.button!==0||"touches"in Q&&Q.touches.length!==1)return!1;const B=Ur(Q);if(C&&!a){const U=B;return l&&(t.context.internalBackdropRef.current||t.context.backdropRef.current)?t.context.internalBackdropRef.current===U||t.context.backdropRef.current===U||Ot(U,f)&&!U?.hasAttribute("data-base-ui-portal"):!0}return!1},escapeKey:C});BA(i&&l===!0,f);const{getReferenceProps:R,getFloatingProps:M,getTriggerProps:z}=vG([O,N]);t.useContextCallback("onNestedDialogOpen",Q=>{T(Q+1)}),t.useContextCallback("onNestedDialogClose",()=>{T(0)}),_.useEffect(()=>(n?.onNestedDialogOpen&&i&&n.onNestedDialogOpen(w),n?.onNestedDialogClose&&!i&&n.onNestedDialogClose(),()=>{n?.onNestedDialogClose&&i&&n.onNestedDialogClose()}),[i,n,w]);const j=_.useMemo(()=>R(p),[R,p]),A=_.useMemo(()=>z(p),[z,p]),P=_.useMemo(()=>M(),[M]);t.useSyncedValues({openMethod:d,activeTriggerProps:j,inactiveTriggerProps:A,popupProps:P,floatingRootContext:S,nestedOpenDialogCount:w})}const jZ={...cG,modal:Pe(e=>e.modal),nested:Pe(e=>e.nested),nestedOpenDialogCount:Pe(e=>e.nestedOpenDialogCount),disablePointerDismissal:Pe(e=>e.disablePointerDismissal),openMethod:Pe(e=>e.openMethod),descriptionElementId:Pe(e=>e.descriptionElementId),titleElementId:Pe(e=>e.titleElementId),viewportElement:Pe(e=>e.viewportElement),role:Pe(e=>e.role)};class AZ extends kA{constructor(t){super(kZ(t),{popupRef:_.createRef(),backdropRef:_.createRef(),internalBackdropRef:_.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:new lx,onOpenChange:void 0,onOpenChangeComplete:void 0},jZ)}setOpen=(t,n)=>{if(n.preventUnmountOnClose=()=>{this.set("preventUnmountingOnClose",!0)},!t&&n.trigger==null&&this.state.activeTriggerId!=null&&(n.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(t,n),n.isCanceled)return;const s={open:t,nativeEvent:n.event,reason:n.reason,nested:this.state.nested};this.state.floatingRootContext.context.events?.emit("openchange",s);const i={open:t},a=n.trigger?.id??null;(a||t)&&(i.activeTriggerId=a,i.activeTriggerElement=n.trigger??null),this.update(i)}}function kZ(e={}){return{...aG(),modal:!0,disablePointerDismissal:!1,popupElement:null,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,role:"dialog",...e}}function OZ(e){const{children:t,open:n,defaultOpen:s=!1,onOpenChange:i,onOpenChangeComplete:a,disablePointerDismissal:l=!1,modal:f=!0,actionsRef:d,handle:p,triggerId:g,defaultTriggerId:y=null}=e,b=rl(!0),x=!!b,S=zn(()=>p?.store??new AZ({open:s,openProp:n,activeTriggerId:y,triggerIdProp:g,modal:f,disablePointerDismissal:l,nested:x})).current;Z8(()=>{n===void 0&&S.state.open===!1&&s===!0&&S.update({open:!0,activeTriggerId:y})}),S.useControlledProp("openProp",n),S.useControlledProp("triggerIdProp",g),S.useSyncedValues({disablePointerDismissal:l,nested:x,modal:f}),S.useContextCallback("onOpenChange",i),S.useContextCallback("onOpenChangeComplete",a);const w=S.useState("payload");NZ({store:S,actionsRef:d,parentContext:b?.store.context});const T=_.useMemo(()=>({store:S}),[S]);return h.jsx(sk.Provider,{value:T,children:typeof t=="function"?t({payload:w}):t})}const lk=_.forwardRef(function(t,n){const{render:s,className:i,id:a,...l}=t,{store:f}=rl(),d=br(a);return f.useSyncedValueWithCleanup("titleElementId",d),zt("h2",t,{ref:n,props:[{id:d},l]})}),$r=OZ,MZ=_.forwardRef(({className:e,...t},n)=>h.jsx(hx,{ref:n,className:ge("fixed inset-0 z-50 bg-black/60 backdrop-blur-sm",e),...t}));MZ.displayName="DialogOverlay";const hr=_.forwardRef(({className:e,children:t,...n},s)=>h.jsxs(ck,{children:[h.jsx(hx,{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm"}),h.jsx(ak,{ref:s,className:ge("fixed z-50 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-panel border border-border rounded-lg shadow-lg max-w-lg w-full p-0",e),...n,children:t})]}));hr.displayName="DialogContent";const pr=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-b border-border",e),...t}));pr.displayName="DialogHeader";const Nn=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-t border-border flex justify-end gap-2",e),...t}));Nn.displayName="DialogFooter";const mr=_.forwardRef(({className:e,...t},n)=>h.jsx(lk,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 uppercase tracking-widest",e),...t}));mr.displayName="DialogTitle";const IZ=_.forwardRef(({className:e,...t},n)=>h.jsx(ok,{ref:n,className:ge("font-mono text-[10px] text-neutral-500",e),...t}));IZ.displayName="DialogDescription";const px=_.forwardRef(({className:e,page:t,totalPages:n,totalItems:s,onPageChange:i,...a},l)=>h.jsxs("div",{ref:l,className:ge("px-5 py-2.5 border-t border-border flex items-center justify-between",e),...a,children:[h.jsxs("span",{className:"font-mono text-[10px] text-neutral-600",children:[s," items · Page ",t," of ",n]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(Ne,{size:"sm",variant:"default",disabled:t<=1,onClick:()=>i(t-1),children:"Prev"}),h.jsx(Ne,{size:"sm",variant:"default",disabled:t>=n,onClick:()=>i(t+1),children:"Next"})]})]}));px.displayName="Pagination";const PZ=_.forwardRef(({className:e,orientation:t="horizontal",...n},s)=>h.jsx("hr",{ref:s,"aria-orientation":t==="vertical"?"vertical":void 0,className:ge("border-none m-0",t==="horizontal"?"h-px w-full bg-border":"w-px h-4 bg-border",e),...n}));PZ.displayName="Separator";const DZ=gi("fixed z-50 bg-panel shadow-lg overflow-auto",{variants:{side:{top:"top-0 left-0 w-full h-[400px] border-b border-border",right:"right-0 top-0 h-full w-[400px] border-l border-border",bottom:"bottom-0 left-0 w-full h-[400px] border-t border-border",left:"left-0 top-0 h-full w-[400px] border-r border-border"}},defaultVariants:{side:"right"}}),zZ=_.forwardRef(({className:e,side:t,children:n,...s},i)=>h.jsxs(ck,{children:[h.jsx(hx,{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm"}),h.jsx(ak,{ref:i,className:ge(DZ({side:t,className:e})),...s,children:n})]}));zZ.displayName="SheetContent";const LZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-b border-border",e),...t}));LZ.displayName="SheetHeader";const UZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-t border-border flex justify-end gap-2",e),...t}));UZ.displayName="SheetFooter";const $Z=_.forwardRef(({className:e,...t},n)=>h.jsx(lk,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 uppercase tracking-widest",e),...t}));$Z.displayName="SheetTitle";const BZ=_.forwardRef(({className:e,...t},n)=>h.jsx(ok,{ref:n,className:ge("text-sm text-neutral-400",e),...t}));BZ.displayName="SheetDescription";const FZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("rounded-md bg-neutral-800 animate-pulse",e),...t}));FZ.displayName="Skeleton";const HZ=_.createContext(void 0);function mx(){const e=_.useContext(HZ);if(e===void 0)throw new Error(yn(64));return e}let qZ=(function(e){return e.activationDirection="data-activation-direction",e.orientation="data-orientation",e})({});const uk={tabActivationDirection:e=>({[qZ.activationDirection]:e})},fk=_.createContext(void 0);function VZ(){const e=_.useContext(fk);if(e===void 0)throw new Error(yn(65));return e}const GZ=_.forwardRef(function(t,n){const{className:s,disabled:i=!1,render:a,value:l,id:f,nativeButton:d=!0,...p}=t,{value:g,getTabPanelIdByValue:y,orientation:b}=mx(),{activateOnFocus:x,highlightedTabIndex:S,onTabActivation:w,setHighlightedTabIndex:T,tabsListElement:C}=VZ(),O=br(f),N=_.useMemo(()=>({disabled:i,id:O,value:l}),[i,O,l]),{compositeProps:R,compositeRef:M,index:z}=ek({metadata:N}),j=l===g,A=_.useRef(!1);Le(()=>{if(A.current){A.current=!1;return}if(!(j&&z>-1&&S!==z))return;const V=C;if(V!=null){const L=Fo(Rt(V));if(L&&Ot(V,L))return}i||T(z)},[j,z,S,T,i,C]);const{getButtonProps:P,buttonRef:Q}=Jc({disabled:i,native:d,focusableWhenDisabled:!0}),B=y(l),U=_.useRef(!1),Z=_.useRef(!1);function G(V){j||i||w(l,Yt(ii,V.nativeEvent,void 0,{activationDirection:"none"}))}function ee(V){j||(z>-1&&!i&&T(z),!i&&x&&(!U.current||U.current&&Z.current)&&w(l,Yt(ii,V.nativeEvent,void 0,{activationDirection:"none"})))}function D(V){if(j||i)return;U.current=!0;function L(){U.current=!1,Z.current=!1}(!V.button||V.button===0)&&(Z.current=!0,Rt(V.currentTarget).addEventListener("pointerup",L,{once:!0}))}return zt("button",t,{state:{disabled:i,active:j,orientation:b},ref:[n,Q,M],props:[R,{role:"tab","aria-controls":B,"aria-selected":j,id:O,onClick:G,onFocus:ee,onPointerDown:D,[tk]:j?"":void 0,onKeyDownCapture(){A.current=!0}},p,P]})});let KZ=(function(e){return e.index="data-index",e.activationDirection="data-activation-direction",e.orientation="data-orientation",e.hidden="data-hidden",e})({});const ZZ={...uk,...ba},YZ=_.forwardRef(function(t,n){const{className:s,value:i,render:a,keepMounted:l=!1,...f}=t,{value:d,getTabIdByPanelValue:p,orientation:g,tabActivationDirection:y,registerMountedTabPanel:b,unregisterMountedTabPanel:x}=mx(),S=br(),w=_.useMemo(()=>({id:S,value:i}),[S,i]),{ref:T,index:C}=dx({metadata:w}),O=i===d,{mounted:N,transitionStatus:R,setMounted:M}=Rp(O),z=!N,j=p(i),A={hidden:z,orientation:g,tabActivationDirection:y,transitionStatus:R},P=_.useRef(null),Q=zt("div",t,{state:A,ref:[n,T,P],props:[{"aria-labelledby":j,hidden:z,id:S,role:"tabpanel",tabIndex:O?0:-1,inert:fx(!O),[KZ.index]:C},f],stateAttributesMapping:ZZ});return xa({open:O,ref:P,onComplete(){O||M(!1)}}),Le(()=>{if(!(z&&!l)&&S!=null)return b(i,S),()=>{x(i,S)}},[z,l,i,S,b,x]),l||N?Q:null}),XZ=_.forwardRef(function(t,n){const{activateOnFocus:s=!1,className:i,loopFocus:a=!0,render:l,...f}=t,{getTabElementBySelectedValue:d,onValueChange:p,orientation:g,value:y,setTabMap:b,tabActivationDirection:x}=mx(),[S,w]=_.useState(0),[T,C]=_.useState(null),O=QZ(y,g,T,d),N=ke((j,A)=>{if(j!==y){const P=O(j);A.activationDirection=P,p(j,A)}}),R={orientation:g,tabActivationDirection:x},M={"aria-orientation":g==="vertical"?"vertical":void 0,role:"tablist"},z=_.useMemo(()=>({activateOnFocus:s,highlightedTabIndex:S,onTabActivation:N,setHighlightedTabIndex:w,tabsListElement:T,value:y}),[s,S,N,w,T,y]);return h.jsx(fk.Provider,{value:z,children:h.jsx(nk,{render:l,className:i,state:R,refs:[n,C],props:[M,f],stateAttributesMapping:uk,highlightedIndex:S,enableHomeAndEndKeys:!0,loopFocus:a,orientation:g,onHighlightedIndexChange:w,onMapChange:b,disabledIndices:Eu})})});function HC(e,t){const{left:n,top:s}=e.getBoundingClientRect(),{left:i,top:a}=t.getBoundingClientRect(),l=n-i,f=s-a;return{left:l,top:f}}function QZ(e,t,n,s){const[i,a]=_.useState(null);return Le(()=>{if(e==null||n==null){a(null);return}const l=s(e);if(l==null){a(null);return}const{left:f,top:d}=HC(l,n);a(t==="horizontal"?f:d)},[t,s,n,e]),_.useCallback(l=>{if(l===e)return"none";if(l==null)return a(null),"none";if(l!=null&&n!=null){const f=s(l);if(f!=null){const{left:d,top:p}=HC(f,n);if(i==null)return a(t==="horizontal"?d:p),"none";if(t==="horizontal"){if(d<i)return a(d),"left";if(d>i)return a(d),"right"}else{if(p<i)return a(p),"up";if(p>i)return a(p),"down"}}}return"none"},[s,t,i,n,e])}const WZ=_.forwardRef(({className:e,...t},n)=>h.jsx(XZ,{ref:n,className:ge("flex items-center gap-0.5",e),...t}));WZ.displayName="TabsList";const JZ=gi("inline-flex items-center justify-center cursor-pointer transition-all outline-none",{variants:{variant:{default:"font-mono text-[10px] text-neutral-500 border border-transparent rounded-sm px-2.5 py-1 hover:text-neutral-300 data-[selected]:text-white data-[selected]:border-border-bright data-[selected]:bg-white/[0.03]",pills:"font-mono text-[10px] text-neutral-500 border border-transparent rounded-full px-3 py-1 hover:text-neutral-300 data-[selected]:text-white data-[selected]:border-border-bright data-[selected]:bg-white/[0.03]"}},defaultVariants:{variant:"default"}}),eY=_.forwardRef(({className:e,variant:t,...n},s)=>h.jsx(GZ,{ref:s,className:ge(JZ({variant:t,className:e})),...n}));eY.displayName="TabsTrigger";const tY=_.forwardRef(({className:e,...t},n)=>h.jsx(YZ,{ref:n,className:ge("outline-none",e),...t}));tY.displayName="TabsContent";const nY=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("font-mono text-[11px] text-neutral-300",e),...t}));nY.displayName="Text";const rY=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("font-mono text-[10px] text-neutral-500",e),...t}));rY.displayName="TextMuted";const sY=_.forwardRef(({className:e,...t},n)=>h.jsx("code",{ref:n,className:ge("font-mono text-[11px] text-white",e),...t}));sY.displayName="TextCode";const oY=_.forwardRef(({className:e,...t},n)=>h.jsx("span",{ref:n,className:ge("font-mono text-[9px] uppercase tracking-wider text-neutral-500",e),...t}));oY.displayName="TextLabel";const iY=_.forwardRef(({className:e,...t},n)=>h.jsx("pre",{ref:n,className:ge("font-mono text-[11px] text-neutral-300 p-3 rounded border border-border bg-panel-alt overflow-x-auto",e),...t}));iY.displayName="CodeBlock";const dk=(...e)=>e.filter((t,n,s)=>!!t&&t.trim()!==""&&s.indexOf(t)===n).join(" ").trim();const aY=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();const cY=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,s)=>s?s.toUpperCase():n.toLowerCase());const qC=e=>{const t=cY(e);return t.charAt(0).toUpperCase()+t.slice(1)};var lY={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const uY=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};const fY=_.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:s,className:i="",children:a,iconNode:l,...f},d)=>_.createElement("svg",{ref:d,...lY,width:t,height:t,stroke:e,strokeWidth:s?Number(n)*24/Number(t):n,className:dk("lucide",i),...!a&&!uY(f)&&{"aria-hidden":"true"},...f},[...l.map(([p,g])=>_.createElement(p,g)),...Array.isArray(a)?a:[a]]));const hk=(e,t)=>{const n=_.forwardRef(({className:s,...i},a)=>_.createElement(fY,{ref:a,iconNode:t,className:dk(`lucide-${aY(qC(e))}`,`lucide-${e}`,s),...i}));return n.displayName=qC(e),n};const dY=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],hY=hk("arrow-left",dY);const pY=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],mY=hk("settings",pY),gY="console:instance-id";function Lt(){const[e,t]=pi(gY,""),n=e.trim();return _.useMemo(()=>({instanceId:n.length>0?n:void 0,rawInstanceId:e,setInstanceId:t,clearInstanceId:()=>t("")}),[n,e,t])}const Jn={stats:e=>["console","stats",e],timeseries:e=>["console","stats","timeseries",e],latency:e=>["console","stats","latency",e],commits:e=>["console","commits",e],commitDetail:(e,t,n)=>["console","commit-detail",e,t,n],timeline:e=>["console","timeline",e],clients:e=>["console","clients",e],eventDetail:(e,t,n)=>["console","event-detail",e,t,n],eventPayload:(e,t,n)=>["console","event-payload",e,t,n],handlers:e=>["console","handlers",e],prunePreview:e=>["console","prune","preview",e],operations:e=>["console","operations",e],apiKeys:e=>["console","api-keys",e],storage:e=>["console","storage",e]};function _i(e,t){return e===0?!1:e??t}function nf(e,t){return t?{...e,instanceId:t}:e}function Sa(e){return encodeURIComponent(String(e))}function Ln(e,t,n){const s=e.endsWith("/")?e.slice(0,-1):e,i=n?.toString();return`${s}${t}${i?`?${i}`:""}`}function rf(e={}){const t=Vt(),{instanceId:n}=Lt(),s=e.instanceId??n,i=nf(e.partitionId?{partitionId:e.partitionId}:{},s);return Wn({queryKey:Jn.stats({partitionId:e.partitionId,instanceId:s}),queryFn:()=>{if(!t)throw new Error("Not connected");return Gu(t.GET("/console/stats",{params:{query:i}}))},enabled:!!t,refetchInterval:_i(e.refetchIntervalMs,5e3)})}function yY(e={},t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=e.instanceId??i;return Wn({queryKey:Jn.timeseries({...e,instanceId:a}),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");const l=new URLSearchParams;e.interval&&l.set("interval",e.interval),e.range&&l.set("range",e.range),e.partitionId&&l.set("partitionId",e.partitionId),a&&l.set("instanceId",a);const f=await fetch(`${s.serverUrl}/console/stats/timeseries?${l}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!f.ok)throw new Error("Failed to fetch timeseries stats");return f.json()},enabled:(t.enabled??!0)&&!!n&&!!s,refetchInterval:_i(t.refetchIntervalMs,3e4)})}function vY(e={},t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=e.instanceId??i;return Wn({queryKey:Jn.latency({...e,instanceId:a}),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");const l=new URLSearchParams;e.range&&l.set("range",e.range),e.partitionId&&l.set("partitionId",e.partitionId),a&&l.set("instanceId",a);const f=await fetch(`${s.serverUrl}/console/stats/latency?${l}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!f.ok)throw new Error("Failed to fetch latency stats");return f.json()},enabled:(t.enabled??!0)&&!!n&&!!s,refetchInterval:_i(t.refetchIntervalMs,3e4)})}function bY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId},i);return Wn({queryKey:Jn.commits({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/commits",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function xY(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.commitDetail(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Commit sequence is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/commits/${Sa(e)}${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch commit detail");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function SY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId,view:e.view,eventType:e.eventType,actorId:e.actorId,clientId:e.clientId,requestId:e.requestId,traceId:e.traceId,table:e.table,outcome:e.outcome,search:e.search,from:e.from,to:e.to},i);return Wn({queryKey:Jn.timeline({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/timeline",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function pk(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId},i);return Wn({queryKey:Jn.clients({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/clients",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function _Y(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.eventDetail(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Event id is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/events/${Sa(e)}${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch event detail");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function wY(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.eventPayload(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Event id is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/events/${Sa(e)}/payload${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch event payload");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function EY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.handlers(i),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/handlers",a),{headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch handlers");return l.json()},enabled:!!t&&!!n})}function TY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.prunePreview(i),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/prune/preview",a),{method:"POST",headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch prune preview");return l.json()},enabled:!!t&&!!n&&(e.enabled??!0)})}function CY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,operationType:e.operationType,partitionId:e.partitionId},i);return Wn({queryKey:Jn.operations({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/operations",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function RY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async({clientId:i,partitionId:a,instanceId:l})=>{if(!e||!t)throw new Error("Not connected");const f=l??n,d=new URLSearchParams;a&&d.set("partitionId",a),f&&d.set("instanceId",f);const p=await fetch(Ln(t.serverUrl,`/console/clients/${Sa(i)}`,d),{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!p.ok)throw new Error("Failed to evict client");return p.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","clients"]}),s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function NY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=await fetch(Ln(t.serverUrl,"/console/prune",i),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!a.ok)throw new Error("Failed to prune");return a.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","commits"]}),s.invalidateQueries({queryKey:["console","timeline"]}),s.invalidateQueries({queryKey:["console","prune","preview"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function jY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=await fetch(Ln(t.serverUrl,"/console/compact",i),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!a.ok)throw new Error("Failed to compact");return a.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function AY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=i.instanceId??n,l=new URLSearchParams;a&&l.set("instanceId",a);const f=await fetch(Ln(t.serverUrl,"/console/notify-data-change",l),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({tables:i.tables,partitionId:i.partitionId})});if(!f.ok)throw new Error("Failed to notify data change");return f.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","commits"]}),s.invalidateQueries({queryKey:["console","timeline"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function kY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.apiKeys({...e,instanceId:i}),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;e.limit!==void 0&&a.set("limit",String(e.limit)),e.offset!==void 0&&a.set("offset",String(e.offset)),e.type&&a.set("type",e.type),e.status&&a.set("status",e.status),e.expiresWithinDays!==void 0&&a.set("expiresWithinDays",String(e.expiresWithinDays)),i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/api-keys",a),{headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch API keys");return l.json()},enabled:!!t&&!!n})}function OY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,"/console/api-keys",a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!l.ok)throw new Error("Failed to create API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function MY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}`,a),{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to revoke API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function IY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,"/console/api-keys/bulk-revoke",a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!l.ok)throw new Error("Failed to bulk revoke API keys");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function PY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}/rotate`,a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to rotate API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function DY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}/rotate/stage`,a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to stage-rotate API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function zY(e={}){const{config:t}=Dt();return Wn({queryKey:Jn.storage({prefix:e.prefix,cursor:e.cursor,limit:e.limit}),queryFn:async()=>{if(!t)throw new Error("Not connected");const n=new URLSearchParams;e.prefix&&n.set("prefix",e.prefix),e.cursor&&n.set("cursor",e.cursor),e.limit&&n.set("limit",String(e.limit));const s=await fetch(Ln(t.serverUrl,"/console/storage",n),{method:"GET",headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok)throw new Error("Failed to list blobs");return s.json()},enabled:!!t,refetchInterval:_i(e.refetchIntervalMs,3e4)})}function LY(){const{config:e}=Dt(),t=_r();return os({mutationFn:async n=>{if(!e)throw new Error("Not connected");const s=encodeURIComponent(n),i=await fetch(Ln(e.serverUrl,`/console/storage/${s}`,new URLSearchParams),{method:"DELETE",headers:{Authorization:`Bearer ${e.token}`}});if(!i.ok)throw new Error("Failed to delete blob");return i.json()},onSuccess:()=>{t.invalidateQueries({queryKey:["console","storage"]})}})}function UY(){const{config:e}=Dt();return async t=>{if(!e)throw new Error("Not connected");const n=encodeURIComponent(t),s=await fetch(Ln(e.serverUrl,`/console/storage/${n}/download`,new URLSearchParams),{method:"GET",headers:{Authorization:`Bearer ${e.token}`}});if(!s.ok)throw new Error("Failed to download blob");const i=await s.blob(),a=URL.createObjectURL(i),l=document.createElement("a");l.href=a,l.download=t.split("/").pop()||t,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a)}}const $Y="console:partition-id";function sf(){const[e,t]=pi($Y,""),n=e.trim();return _.useMemo(()=>({partitionId:n.length>0?n:void 0,rawPartitionId:e,setPartitionId:t,clearPartitionId:()=>t("")}),[n,e,t])}const VC={refreshInterval:5,timeFormat:"relative",showSparklines:!0,pageSize:20};function of(){const[e,t]=pi("console:preferences",VC);return{preferences:e,setPreferences:t,updatePreference:(i,a)=>{t(l=>({...l,[i]:a}))},resetPreferences:()=>{t(VC)}}}const BY=[{value:5,label:"5 seconds"},{value:10,label:"10 seconds"},{value:30,label:"30 seconds"},{value:60,label:"1 minute"},{value:0,label:"Manual only"}],FY=[{value:10,label:"10"},{value:20,label:"20"},{value:50,label:"50"},{value:100,label:"100"}],gx="syncular-console-root";function HY(e){e.classList.add(gx)}const qY=[{suffix:"",label:"Command"},{suffix:"/stream",label:"Stream"},{suffix:"/fleet",label:"Fleet"},{suffix:"/ops",label:"Ops"},{suffix:"/storage",label:"Storage"},{suffix:"/config",label:"Config"}];function VY(e){const t=e?.trim()??"";return!t||t==="/"?"":(t.startsWith("/")?t:`/${t}`).replace(/\/+$/g,"")}function Uy(e,t){return e?t?`${e}${t}`:e:t||"/"}function GY({basePath:e,appHref:t,modeBadge:n}){const{connect:s,config:i,isConnected:a,isConnecting:l}=Dt(),{preferences:f}=of(),{instanceId:d,rawInstanceId:p,setInstanceId:g,clearInstanceId:y}=Lt(),{partitionId:b,rawPartitionId:x,setPartitionId:S,clearPartitionId:w}=sf(),T=vr({select:P=>P.location.pathname}),{data:C}=rf({refetchIntervalMs:f.refreshInterval*1e3,partitionId:b,instanceId:d}),O=VY(e),N=_.useMemo(()=>qY.map(P=>({...P,id:Uy(O,P.suffix)})),[O]),R=Uy(O,""),M=Uy(O,"/config"),z=l?"connecting":a?"connected":i?"disconnected":"not-configured",j=N.find(P=>P.suffix===""?T===R||T===`${R}/`:T.startsWith(P.id))?.id??R,A=C?[{label:"HEAD",value:`#${C.maxCommitSeq}`},{label:"COMMITS",value:`${C.commitCount}`},{label:"CHANGES",value:`${C.changeCount}`},{label:"CLIENTS",value:`${C.activeClientCount}/${C.clientCount}`}]:[];return h.jsxs("div",{className:`${gx} h-screen bg-background text-foreground flex flex-col`,children:[h.jsx(SZ,{brand:h.jsx(bc,{to:R,children:h.jsx(xZ,{label:"console"})}),center:h.jsx(hZ,{items:N,activeId:j,renderItem:(P,{active:Q})=>h.jsx(bc,{to:P.id,children:h.jsx(rk,{active:Q,children:P.label})},P.id)}),right:h.jsxs("div",{className:"flex items-center gap-2",children:[n?h.jsx(mn,{variant:"flow",className:"hidden md:inline-flex px-2 py-1 text-[10px]",children:n}):null,h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"font-mono text-[9px] text-neutral-500 uppercase tracking-wide",children:"Instance"}),h.jsx(Kn,{variant:"mono",value:p,onChange:P=>g(P.target.value),onBlur:P=>g(P.target.value.trim()),placeholder:"all",className:"h-7 w-[110px] px-2 py-1"}),d?h.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px]",onClick:y,children:"All"}):null]}),h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"font-mono text-[9px] text-neutral-500 uppercase tracking-wide",children:"Partition"}),h.jsx(Kn,{variant:"mono",value:x,onChange:P=>S(P.target.value),onBlur:P=>S(P.target.value.trim()),placeholder:"all",className:"h-7 w-[110px] px-2 py-1"}),b?h.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px]",onClick:w,children:"All"}):null]}),h.jsx(R8,{state:z}),h.jsx(bc,{to:M,children:h.jsx(Ne,{variant:T===M?"secondary":"ghost",size:"icon",children:h.jsx(mY,{className:"h-3 w-3"})})}),t?h.jsxs("a",{href:t,className:dZ,children:[h.jsx(hY,{className:"h-3 w-3"}),"Go to app"]}):null]})}),h.jsx("main",{className:"flex-1 overflow-auto pb-[32px]",children:h.jsx("div",{className:"min-h-full",children:a||T===M?h.jsx("div",{style:{animation:"pageIn 0.3s ease-out"},children:h.jsx(YN,{})},T):h.jsx(KY,{configPath:M,hasSavedConfig:!!i,isConnecting:l,onConnect:()=>{s()}})})}),a&&h.jsx(Bj,{isLive:a,metrics:A,uptime:"--"})]})}function KY({configPath:e,hasSavedConfig:t,isConnecting:n,onConnect:s}){return h.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[h.jsx("p",{className:"mb-4 text-foreground-muted",children:"Not connected to a @syncular server"}),h.jsxs("div",{className:"flex items-center gap-2",children:[t&&h.jsx(Ne,{variant:"default",onClick:s,disabled:n,children:n?"Connecting...":"Connect"}),h.jsx(bc,{to:e,children:h.jsx(Ne,{variant:"link",children:"Configure connection"})})]})]})}const uo=NH({component:GY});function ZY(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).get("swServer")==="1"}function YY(e={}){const{maxEvents:t=100,enabled:n=!0,staleAfterMs:s=65e3,replayLimit:i=100,partitionId:a,instanceId:l}=e,{config:f,isConnected:d}=Dt(),{instanceId:p}=Lt(),g=l??p,[y,b]=_.useState([]),[x,S]=_.useState(!1),[w,T]=_.useState("disconnected"),[C,O]=_.useState(null),N=_.useRef(null),R=_.useRef(null),M=_.useRef(null),z=_.useRef(0),j=_.useRef(0),A=_.useRef(null),P=_.useRef(null),Q=_.useCallback(()=>{b([]),A.current=null,P.current=null},[]);return _.useEffect(()=>{if(!n||!d||!f?.serverUrl||!f?.token)return;let B=!1;const U=Number.isFinite(i)?Math.max(1,Math.min(500,Math.floor(i))):100;if(ZY()||typeof WebSocket>"u"){T("connecting"),S(!1);let V=null,L=!1;const I=async()=>{if(!(B||L)){L=!0;try{const H=new URL(f.serverUrl,window.location.origin),W=H.pathname.endsWith("/")?H.pathname.slice(0,-1):H.pathname;H.pathname=`${W}/console/events`,H.search="",H.searchParams.set("limit",String(U)),H.searchParams.set("offset","0"),a&&H.searchParams.set("partitionId",a);const Y=await fetch(H.toString(),{headers:{Authorization:`Bearer ${f.token}`}});if(!Y.ok)throw new Error(`Live event polling failed (${Y.status})`);const ae=await Y.json(),fe=(Array.isArray(ae.items)?ae.items:[]).filter(Me=>g?Me.instanceId===g:!0).sort((Me,_e)=>Me.eventId-_e.eventId),Se=P.current??-1,pe=fe.filter(Me=>Me.eventId>Se);if(pe.length>0){const Me=pe.map(re=>({type:re.eventType,timestamp:re.createdAt,data:re})).reverse();b(re=>[...Me,...re].slice(0,t));const _e=pe[pe.length-1];P.current=_e.eventId,A.current=_e.createdAt}else if(fe.length>0){const Me=fe[fe.length-1];P.current=Math.max(P.current??-1,Me.eventId),A.current=Me.createdAt}O(null),S(!0),T("connected")}catch(H){B||(S(!1),T("disconnected"),O(H instanceof Error?H:new Error("Live event polling failed")))}finally{L=!1}}};return I(),V=setInterval(()=>{I()},2e3),()=>{B=!0,V&&clearInterval(V),S(!1),T("disconnected")}}const G=()=>{R.current&&(clearTimeout(R.current),R.current=null)},ee=()=>{M.current&&(clearInterval(M.current),M.current=null)},D=()=>{if(B||R.current)return;z.current+=1;const V=Math.min(3e4,1e3*2**Math.max(0,z.current-1)),L=Math.floor(V*.2*Math.random()),I=V+L;R.current=setTimeout(()=>{R.current=null,B||q()},I)},K=()=>{j.current=Date.now(),S(!0),T("connected")},q=()=>{if(B)return;T("connecting"),G();const V=(()=>{const I=new URL(f.serverUrl,window.location.origin);I.protocol=I.protocol==="https:"?"wss:":"ws:";const H=I.pathname.endsWith("/")?I.pathname.slice(0,-1):I.pathname;return I.pathname=`${H}/console/events/live`,I.search="",I.searchParams.set("token",f.token),A.current&&I.searchParams.set("since",A.current),I.searchParams.set("replayLimit",String(U)),a&&I.searchParams.set("partitionId",a),g&&I.searchParams.set("instanceId",g),I.toString()})(),L=new WebSocket(V);N.current=L,L.onopen=()=>{if(B){L.close();return}z.current=0,K(),O(null),ee(),M.current=setInterval(()=>{const I=N.current;if(!I||I.readyState!==WebSocket.OPEN)return;const H=j.current;!H||Date.now()-H<=s||(S(!1),T("stale"),I.close())},1e3)},L.onclose=()=>{B||(S(!1),T("disconnected"),ee(),D())},L.onerror=()=>{B||O(new Error("WebSocket connection failed"))},L.onmessage=I=>{try{const H=JSON.parse(I.data),W=H.type;if(K(),W==="connected"||W==="heartbeat")return;const Y={type:W,timestamp:H.timestamp||new Date().toISOString(),data:H};if(a&&Y.data.partitionId!==a||g&&Y.data.instanceId!==g)return;const ae=Date.parse(A.current??""),se=Date.parse(Y.timestamp);Number.isFinite(se)&&(!Number.isFinite(ae)||se>ae)&&(A.current=Y.timestamp),b(fe=>[Y,...fe].slice(0,t))}catch{}}};return q(),()=>{B=!0,G(),ee(),N.current&&(N.current.close(),N.current=null),S(!1),T("disconnected")}},[n,d,f?.serverUrl,f?.token,t,a,g,i,s]),{events:y,isConnected:x,connectionState:w,error:C,clearEvents:Q}}function XY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=i.toString(),l=await fetch(`${t.serverUrl}/console/events${a?`?${a}`:""}`,{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to clear events");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","events"]})}})}const QY=_.createContext(null);function mk(){const[e,t]=pi("console:time-range","24h");return{range:e,setRange:t}}const WY=[{hint:"ios",type:"mobile"},{hint:"android",type:"mobile"},{hint:"mobile",type:"mobile"},{hint:"tablet",type:"tablet"},{hint:"desktop",type:"desktop"},{hint:"mac",type:"desktop"},{hint:"windows",type:"desktop"},{hint:"linux",type:"desktop"},{hint:"browser",type:"browser"},{hint:"web",type:"browser"},{hint:"server",type:"server"},{hint:"api",type:"server"},{hint:"iot",type:"iot"},{hint:"sensor",type:"iot"}];function JY(e){const t=e.toLowerCase();for(const n of WY)if(t.includes(n.hint))return n.type;return"client"}function eX(e){const t=e.toLowerCase();return t.includes("pglite")?"PGlite":t.includes("sqlite")||t.includes("wa-sqlite")?"SQLite":t.includes("postgres")||t.includes("pg")?"PostgreSQL":"unknown"}function tX(e,t){return typeof e.lagCommitCount=="number"?Math.max(0,e.lagCommitCount):t?Math.max(0,t.maxCommitSeq-e.cursor):0}function nX(e,t){return e.activityState==="stale"?"offline":t>0?"syncing":"online"}function rX(e,t){return e.length<=16?e:`${e.slice(0,12)}-${t+1}`}function sX(e,t,n={}){const s=n.maxNodes??10;return e.slice(0,s).map((i,a)=>{const l=tX(i,t),f=nX(i,l);return{id:rX(i.clientId,a),type:JY(i.clientId),status:f,cursor:Math.max(0,i.cursor),actor:i.actorId,mode:i.connectionMode,dialect:eX(i.clientId),scopes:Object.keys(i.effectiveScopes||{}),lastSeen:i.updatedAt}})}const oX={enabled:!1,thresholds:{p90Latency:500,errorRate:5,clientLag:100}};function GC(e,t="relative"){if(t==="absolute")return new Date(e).toLocaleString();const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3);return a<60?`${a}s ago`:a<3600?`${Math.floor(a/60)}m ago`:a<86400?`${Math.floor(a/3600)}h ago`:`${Math.floor(a/86400)}d ago`}function iX(e){const t=e.length>1&&e.endsWith("/")?e.slice(0,-1):e;return t==="/console"||t.startsWith("/console/")?"/console/stream":"/stream"}function aX(){const e=dp(),t=_.useMemo(()=>typeof window>"u"?"/stream":iX(window.location.pathname),[]),n=mk(),{range:s}=n,{preferences:i}=of(),{partitionId:a}=sf(),l=i.refreshInterval*1e3,[f]=pi("console:alert-config",oX),[d,p]=_.useState("1h"),{data:g}=rf({refetchIntervalMs:l,partitionId:a}),{data:y}=yY({range:s,partitionId:a},{refetchIntervalMs:l}),{data:b}=vY({range:s,partitionId:a},{refetchIntervalMs:l}),{data:x}=bY({limit:5,partitionId:a},{refetchIntervalMs:l}),{data:S}=pk({limit:12,offset:0,partitionId:a},{refetchIntervalMs:l}),{events:w,isConnected:T}=YY({maxEvents:8,partitionId:a}),C=_.useMemo(()=>{const U=y?.buckets??[];let Z=0,G=0;for(const D of U)Z+=D.pushCount+D.pullCount,G+=D.errorCount;const ee=Z>0?G/Z*100:0;return{totalEvents:Z,errorRate:ee}},[y?.buckets]),O=_.useMemo(()=>S?.items?sX(S.items,g,{maxNodes:12}):[],[S?.items,g]),N=O.filter(U=>U.status!=="offline").length,R=O.filter(U=>U.status==="offline").length,M=_.useMemo(()=>g?[{label:"Ops (Range)",value:C.totalEvents,color:"flow"},{label:"P50 Latency",value:b?.push?.p50??0,unit:"ms",color:"healthy"},{label:"Error Rate",value:`${C.errorRate.toFixed(1)}%`,color:C.errorRate>0?"offline":"muted"},{label:"Active Clients",value:g.activeClientCount,color:"syncing"},{label:"Pending",value:g.maxActiveClientCursor!==null&&g.maxCommitSeq>0?g.maxCommitSeq-(g.minActiveClientCursor??0):0,color:"relay"}]:[],[g,b,C.errorRate,C.totalEvents]),z=_.useMemo(()=>w.map(U=>({type:U.type.toUpperCase(),actor:U.data?.actorId??"",table:(U.data?.tables??[])[0]??"",time:GC(U.timestamp,i.timeFormat)})),[w,i.timeFormat]),j=_.useMemo(()=>{const U=y?.buckets;if(!U?.length)return[];const Z=Math.max(...U.map(G=>Math.max(G.pushCount,G.pullCount)),1);return U.map(G=>({pushPercent:Z>0?G.pushCount/Z*100:0,pullPercent:Z>0?G.pullCount/Z*100:0}))},[y?.buckets]),A=_.useMemo(()=>{if(!b)return[];const U=Math.max(b.push.p50,b.push.p90,b.push.p99,b.pull.p50,b.pull.p90,b.pull.p99,1);return[{label:"P50",pushMs:b.push.p50,pullMs:b.pull.p50,pushBarPercent:b.push.p50/U*100,pullBarPercent:b.pull.p50/U*100},{label:"P90",pushMs:b.push.p90,pullMs:b.pull.p90,pushBarPercent:b.push.p90/U*100,pullBarPercent:b.pull.p90/U*100},{label:"P99",pushMs:b.push.p99,pullMs:b.pull.p99,pushBarPercent:b.push.p99/U*100,pullBarPercent:b.pull.p99/U*100}]},[b]),P=_.useMemo(()=>x?.items?x.items.map(U=>({seq:U.commitSeq,actor:U.actorId,changes:U.changeCount,tables:(U.affectedTables??[]).join(", "),time:GC(U.createdAt,i.timeFormat)})):[],[x?.items,i.timeFormat]),Q=_.useMemo(()=>Math.max(0,100-C.errorRate),[C.errorRate]),B=_.useMemo(()=>{if(!f.enabled||!g)return[];const U=[];return b?.push?.p90&&b.push.p90>f.thresholds.p90Latency&&U.push(`P90 push latency (${b.push.p90}ms) exceeds threshold (${f.thresholds.p90Latency}ms)`),g.minActiveClientCursor!==null&&g.maxCommitSeq-g.minActiveClientCursor>f.thresholds.clientLag&&U.push(`Client lag (${g.maxCommitSeq-g.minActiveClientCursor}) exceeds threshold (${f.thresholds.clientLag})`),C.errorRate>f.thresholds.errorRate&&U.push(`Error rate (${C.errorRate.toFixed(1)}%) exceeds threshold (${f.thresholds.errorRate}%)`),U},[f,g,b,C.errorRate]);return g?h.jsx(QY.Provider,{value:n,children:h.jsxs("div",{className:"flex flex-col",children:[B.length>0&&h.jsx("div",{className:"px-6 pb-4",children:h.jsxs(In,{variant:"destructive",children:[h.jsx(tf,{children:"Threshold Exceeded"}),h.jsx(Pn,{children:B.map((U,Z)=>h.jsx("span",{className:"block",children:U},Z))})]})}),h.jsx(zA,{clients:O,totalNodes:O.length+2,onlineCount:N,offlineCount:R,relayClientIds:[]}),h.jsx(Kj,{items:M}),h.jsxs("div",{className:"flex",children:[h.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[h.jsx("div",{className:"border-b border-border border-r border-border",children:h.jsx(xj,{bars:j,activeRange:d,onRangeChange:p})}),h.jsx("div",{className:"border-b border-border border-r border-border",children:h.jsx(Zj,{buckets:A,successRate:Q})}),h.jsx("div",{className:"border-r border-border",children:h.jsx(Fj,{commits:P,onViewAll:()=>e({href:t})})})]}),h.jsx(Yj,{entries:z,isConnected:T,maxVisible:20,maxHeight:"calc(100vh - 200px)"})]})]})}):h.jsx("div",{className:"flex items-center justify-center py-24",children:h.jsx(Pt,{size:"lg"})})}function cX(){return h.jsx(aX,{})}function lX({children:e}){return h.jsxs("div",{className:"space-y-4 px-5 py-5",children:[h.jsx(uX,{}),h.jsx(mX,{}),h.jsx(gX,{}),e]})}function uX(){const{clearError:e,config:t,connect:n,disconnect:s,error:i,isConnected:a,isConnecting:l}=Dt(),[f,d]=_.useState(t?.serverUrl??"/api"),[p,g]=_.useState(t?.token??""),[y,b]=_.useState(null),[x,S]=_.useState(!1),[w,T]=_.useState(null),[C,O]=pi("console:disconnect-clear-saved-config",!1);_.useEffect(()=>{const j=new URLSearchParams(window.location.search),A=j.get("token"),P=j.get("server");A&&(g(A),window.history.replaceState({},"",window.location.pathname)),P&&d(P)},[]),_.useEffect(()=>{t?.serverUrl&&d(t.serverUrl),t?.token&&g(t.token)},[t?.serverUrl,t?.token]),_.useEffect(()=>{T(null)},[]);const N=async()=>{e(),b(null);const j=await n({serverUrl:f.trim(),token:p.trim()},{persistOverride:!0});T(j?"Connected successfully and configuration saved.":"Failed to connect with the provided settings.")},R=()=>{s({clearSavedConfig:C}),C&&(d("/api"),g("")),T(C?"Disconnected and saved credentials cleared.":"Disconnected."),b(null)},M=async()=>{S(!0),b(null),T(null);const j=performance.now();try{const A=f.trim(),P=p.trim();if(!A||!P)throw new Error("Missing server URL or token");if(!(await fetch(`${A}/console/stats`,{headers:{Authorization:`Bearer ${P}`}})).ok)throw new Error("Failed to connect");b(Math.round(performance.now()-j))}catch{b(-1)}finally{S(!1)}},z=i??w??(y!==null?y<0?"Connection failed":`Connection successful (${y}ms latency)`:void 0);return h.jsx(Hj,{isConnected:a,isConnecting:l,isTestingConnection:x,serverUrl:f,onServerUrlChange:d,consoleToken:p,onConsoleTokenChange:g,onSaveAndConnect:N,onDisconnect:R,onTestConnection:M,statusMessage:z,children:h.jsx("div",{className:"px-5 pb-5 -mt-2",children:h.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2",children:[h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] text-neutral-400",children:"Clear saved credentials on disconnect"}),h.jsx("p",{className:"font-mono text-[9px] text-neutral-500",children:"Removes stored server URL and token from this browser."})]}),h.jsx(Sp,{checked:C,onCheckedChange:O})]})})})}const fX=1440*60*1e3;function KC(e){const t=e.trim();if(!t)return null;const n=Number.parseInt(t,10);return!Number.isInteger(n)||n<=0?null:n}function $y(e){if(!e)return"Never";const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():"Invalid date"}function dX(e){return e.length===0?"all scopes":e.length<=2?e.join(", "):`${e.slice(0,2).join(", ")} +${e.length-2}`}function hX(e,t){if(e.revokedAt)return"revoked";if(!e.expiresAt)return"active";const n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return"active";const s=Date.now();return n<=s?"expired":n<=s+t*fX?"expiring":"active"}function pX(e){return e==="revoked"?"destructive":e==="expired"?"offline":e==="expiring"?"syncing":"healthy"}function mX(){const[e,t]=_.useState("all"),[n,s]=_.useState("all"),[i,a]=_.useState("14"),[l,f]=_.useState(!1),[d,p]=_.useState(!1),[g,y]=_.useState(""),[b,x]=_.useState("relay"),[S,w]=_.useState(""),[T,C]=_.useState(""),[O,N]=_.useState(""),[R,M]=_.useState(null),[z,j]=_.useState([]),[A,P]=_.useState(null),[Q,B]=_.useState(null),[U,Z]=_.useState(null),[G,ee]=_.useState(null),[D,K]=_.useState(null),[q,V]=_.useState(null),[L,I]=_.useState(null),H=_.useMemo(()=>KC(i),[i]),W=H??14,Y=_.useMemo(()=>KC(O),[O]),ae=O.trim().length>0,se=!ae||Y!==null,fe=_.useMemo(()=>({type:e==="all"?void 0:e,status:n==="all"?void 0:n,expiresWithinDays:n==="expiring"?W:void 0}),[e,n,W]),{data:Se,isLoading:pe,error:Me}=kY(fe),_e=OY(),re=IY(),he=MY(),ie=PY(),we=DY();_.useEffect(()=>{const me=new Set((Se?.items??[]).map(Te=>Te.keyId));j(Te=>Te.filter(qe=>me.has(qe)))},[Se?.items]);const ye=async()=>{try{const me=T.split(",").map(qe=>qe.trim()).filter(qe=>qe.length>0),Te=await _e.mutateAsync({name:g,keyType:b,actorId:S||void 0,scopeKeys:me.length>0?me:void 0,expiresInDays:ae?Y??void 0:void 0});M(Te.secretKey),y(""),w(""),C(""),N("")}catch{}},xe=me=>{navigator.clipboard.writeText(me),B(me),setTimeout(()=>B(null),2e3)},ve=async()=>{if(U)try{await he.mutateAsync(U)}finally{Z(null)}},Ie=async()=>{if(z.length!==0)try{const me=await re.mutateAsync({keyIds:z});P(me),j([])}catch{}},Ue=async()=>{if(G)try{const me=await we.mutateAsync(G.keyId);K({oldKeyId:G.keyId,oldKeyName:G.name,secretKey:me.secretKey})}catch{}},Ee=async()=>{if(D)try{await he.mutateAsync(D.oldKeyId)}finally{K(null),ee(null)}},Ve=async()=>{if(q)try{const me=await ie.mutateAsync(q);I(me.secretKey)}finally{V(null)}};if(pe)return h.jsx("div",{className:"flex h-[200px] items-center justify-center",children:h.jsx(Pt,{size:"lg"})});if(Me)return h.jsx("div",{className:"flex h-[200px] items-center justify-center",children:h.jsxs("p",{className:"text-danger",children:["Failed to load API keys: ",Me.message]})});const Qe=(Se?.items??[]).filter(me=>me.revokedAt===null).map(me=>me.keyId),Be=Qe.length>0&&Qe.every(me=>z.includes(me)),We=z.length>0,He=(Se?.items??[]).filter(me=>z.includes(me.keyId)).map(me=>me.name);return h.jsxs(h.Fragment,{children:[h.jsxs(Wb,{title:"API Keys",description:"Issue, rotate, revoke, and audit key lifecycle state.",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs(Ne,{size:"sm",variant:"destructive",onClick:()=>p(!0),disabled:z.length===0,children:["Revoke Selected (",z.length,")"]}),h.jsx(Ne,{size:"sm",onClick:()=>f(!0),children:"Create Key"})]}),children:[h.jsxs("div",{className:"mb-4 grid gap-3 lg:grid-cols-3",children:[h.jsxs(ps,{children:[h.jsx(es,{children:"Type filter"}),h.jsxs(dh,{value:[e],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="all"||Te==="relay"||Te==="proxy"||Te==="admin")&&t(Te)},children:[h.jsx(Dr,{value:"all",children:"all"}),h.jsx(Dr,{value:"relay",children:"relay"}),h.jsx(Dr,{value:"proxy",children:"proxy"}),h.jsx(Dr,{value:"admin",children:"admin"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Status filter"}),h.jsxs(dh,{value:[n],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="all"||Te==="active"||Te==="revoked"||Te==="expiring")&&s(Te)},children:[h.jsx(Dr,{value:"all",children:"all"}),h.jsx(Dr,{value:"active",children:"active"}),h.jsx(Dr,{value:"revoked",children:"revoked"}),h.jsx(Dr,{value:"expiring",children:"expiring"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-expiring-window",children:"Expiring window (days)"}),h.jsx(pc,{children:"Used when status filter is set to expiring."}),h.jsx(Kn,{id:"api-key-expiring-window",placeholder:"14",value:i,inputMode:"numeric",onChange:me=>a(me.target.value)}),H===null&&i.trim().length>0?h.jsx("p",{className:"font-mono text-[10px] text-offline",children:"Enter a positive whole number."}):null]})]}),Se?.items.length===0?h.jsx(Qb,{message:"No API keys match the current filters."}):h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:h.jsx(Uv,{checked:Be,indeterminate:!Be&&We&&Qe.length>0,onCheckedChange:me=>{j(me?Qe:[])},"aria-label":"Select all active keys"})}),h.jsx(yt,{children:"NAME"}),h.jsx(yt,{children:"TYPE"}),h.jsx(yt,{children:"KEY PREFIX"}),h.jsx(yt,{children:"ACTOR"}),h.jsx(yt,{children:"SCOPES"}),h.jsx(yt,{children:"CREATED"}),h.jsx(yt,{children:"LAST USED"}),h.jsx(yt,{children:"EXPIRES"}),h.jsx(yt,{children:"STATUS"}),h.jsx(yt,{children:"ACTIONS"})]})}),h.jsx(Xu,{children:(Se?.items??[]).map(me=>{const Te=hX(me,W);return h.jsxs(io,{children:[h.jsx(vt,{children:h.jsx(Uv,{checked:z.includes(me.keyId),onCheckedChange:qe=>{j(ht=>qe?[...new Set([...ht,me.keyId])]:ht.filter(lt=>lt!==me.keyId))},"aria-label":`Select ${me.name}`,disabled:me.revokedAt!==null})}),h.jsx(vt,{className:"font-medium",children:me.name}),h.jsx(vt,{children:h.jsx(mn,{variant:me.keyType==="admin"?"flow":me.keyType==="proxy"?"ghost":"relay",children:me.keyType})}),h.jsx(vt,{children:h.jsxs("code",{className:"font-mono text-[11px]",children:[me.keyPrefix,"..."]})}),h.jsx(vt,{className:"text-neutral-500",children:me.actorId??"-"}),h.jsx(vt,{className:"max-w-[220px] text-neutral-500",children:h.jsx("code",{className:"font-mono text-[10px]",children:dX(me.scopeKeys)})}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.createdAt)}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.lastUsedAt)}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.expiresAt)}),h.jsx(vt,{children:h.jsx(mn,{variant:pX(Te),children:Te})}),h.jsx(vt,{children:h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>ee(me),disabled:me.revokedAt!==null,children:"Stage"}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>V(me.keyId),disabled:me.revokedAt!==null,children:"Rotate"}),h.jsx(Ne,{variant:"destructive",size:"sm",onClick:()=>Z(me.keyId),disabled:me.revokedAt!==null,children:"Revoke"})]})})]},me.keyId)})})]})]}),h.jsx($r,{open:l,onOpenChange:f,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Create API Key"})}),R?h.jsx(ZC,{copiedKeyId:Q,onClose:()=>{M(null),f(!1)},onCopy:xe,secretKey:R,warning:"Copy this key now. You will not be able to view it again."}):h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-name",children:"Name"}),h.jsx(Kn,{id:"api-key-name",placeholder:"Backend Relay Key",value:g,onChange:me=>y(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Key type"}),h.jsxs(dh,{value:[b],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="relay"||Te==="proxy"||Te==="admin")&&x(Te)},children:[h.jsx(Dr,{value:"relay",children:"relay"}),h.jsx(Dr,{value:"proxy",children:"proxy"}),h.jsx(Dr,{value:"admin",children:"admin"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-actor-id",children:"Actor ID (optional)"}),h.jsx(pc,{children:"Pin this key to a fixed actor ID"}),h.jsx(Kn,{id:"api-key-actor-id",placeholder:"actor-123",value:S,onChange:me=>w(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-scope-keys",children:"Scope keys (optional)"}),h.jsx(pc,{children:"Comma-separated list of allowed scope keys"}),h.jsx(Kn,{id:"api-key-scope-keys",placeholder:"scope-a, scope-b",value:T,onChange:me=>C(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-expires-days",children:"Expires in days (optional)"}),h.jsx(pc,{children:"Leave empty to keep the key non-expiring."}),h.jsx(Kn,{id:"api-key-expires-days",placeholder:"30",value:O,inputMode:"numeric",onChange:me=>N(me.target.value)}),se?null:h.jsx("p",{className:"font-mono text-[10px] text-offline",children:"Enter a positive whole number."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>f(!1),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:ye,disabled:_e.isPending||!g||!se,children:_e.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Creating..."]}):"Create"})]})]})]})}),h.jsx($r,{open:d,onOpenChange:me=>{p(me),me||P(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Bulk Revoke API Keys"})}),A?h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[h.jsx(In,{variant:"destructive",children:h.jsxs(Pn,{children:["Requested ",A.requestedCount," keys. Revoked"," ",A.revokedCount,", already revoked"," ",A.alreadyRevokedCount,", not found"," ",A.notFoundCount,"."]})}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"primary",onClick:()=>{p(!1),P(null)},children:"Done"})})]}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:"This revokes selected keys immediately and cannot be undone."})}),h.jsxs("p",{className:"font-mono text-[10px] text-neutral-500",children:["Selected keys: ",He.slice(0,5).join(", "),He.length>5?` +${He.length-5} more`:""]})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>p(!1),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:Ie,disabled:re.isPending||z.length===0,children:re.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking..."]}):"Revoke Selected"})]})]})]})}),h.jsx($r,{open:G!==null||D!==null,onOpenChange:()=>{ee(null),K(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Stage Rotate API Key"})}),D?h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsx(In,{variant:"default",children:h.jsxs(Pn,{children:["Replacement key created for ",D.oldKeyName,". The old key is still active until you revoke it."]})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("code",{className:"flex-1 rounded-md border border-border bg-surface p-3 font-mono text-[11px] text-white break-all",children:D.secretKey}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>xe(D.secretKey),children:Q===D.secretKey?"Copied":"Copy"})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>{K(null),ee(null)},children:"Keep Old Key Active"}),h.jsx(Ne,{variant:"destructive",onClick:Ee,disabled:he.isPending,children:he.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking Old Key..."]}):"Finalize and Revoke Old Key"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"px-5 py-4",children:h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"Staged rotation creates a replacement key now and keeps the current key active until you explicitly revoke it."})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>ee(null),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:Ue,disabled:we.isPending||!G,children:we.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Staging..."]}):"Create Replacement Key"})]})]})]})}),h.jsx($r,{open:U!==null,onOpenChange:()=>Z(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Revoke API Key"})}),h.jsx("div",{className:"px-5 py-4",children:h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:"Revoking a key immediately invalidates it for all requests."})})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>Z(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:ve,disabled:he.isPending,children:he.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking..."]}):"Revoke"})]})]})}),h.jsx($r,{open:q!==null||L!==null,onOpenChange:()=>{V(null),I(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Rotate API Key"})}),L?h.jsx(ZC,{copiedKeyId:Q,onClose:()=>I(null),onCopy:xe,secretKey:L,warning:"The previous key has been invalidated. Store this replacement securely."}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"px-5 py-4",children:h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"Rotating a key invalidates the previous secret immediately."})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>V(null),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:Ve,disabled:ie.isPending,children:ie.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Rotating..."]}):"Rotate"})]})]})]})})]})}function gX(){const{preferences:e,updatePreference:t,resetPreferences:n}=of(),s=[{type:"filter",label:"Auto-refresh interval",options:BY.map(i=>({id:`${i.value}`,label:i.label})),activeId:`${e.refreshInterval}`,onActiveChange:i=>t("refreshInterval",Number.parseInt(i,10))},{type:"filter",label:"Items per page",options:FY.map(i=>({id:`${i.value}`,label:i.label})),activeId:`${e.pageSize}`,onActiveChange:i=>t("pageSize",Number.parseInt(i,10))},{type:"filter",label:"Time format",options:[{id:"relative",label:"Relative"},{id:"absolute",label:"Absolute"}],activeId:e.timeFormat,onActiveChange:i=>t("timeFormat",i)},{type:"toggle",label:"Show sparklines",description:"Display mini trend charts in dashboard metric cards",checked:e.showSparklines,onCheckedChange:i=>t("showSparklines",i)}];return h.jsx(Xj,{rows:s,onResetDefaults:n})}function ZC({copiedKeyId:e,onClose:t,onCopy:n,secretKey:s,warning:i}){return h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:i})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("code",{className:"flex-1 rounded-md border border-border bg-surface p-3 font-mono text-[11px] text-white break-all",children:s}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>n(s),children:e===s?"Copied":"Copy"})]}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"primary",onClick:t,children:"Done"})})]})}function yX(e){const t=e.toLowerCase();return t.includes("mobile")||t.includes("ios")||t.includes("android")?"mobile":t.includes("tablet")?"tablet":t.includes("desktop")||t.includes("laptop")?"desktop":t.includes("edge")?"edge":t.includes("iot")?"iot":"desktop"}function vX(e){const t=e.toLowerCase();return t.includes("pglite")?"PGlite":t.includes("wa-sqlite")||t.includes("sqlite")?"SQLite":t.includes("postgres")||t.includes("pg")?"PostgreSQL":"unknown"}function bX(e,t){if(t==="absolute")return new Date(e).toLocaleString();try{const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3),l=Math.floor(a/60),f=Math.floor(l/60),d=Math.floor(f/24);return a<60?"just now":l<60?`${l}m ago`:f<24?`${f}h ago`:`${d}d ago`}catch{return e}}function xX(e,t,n){return{id:e.clientId,type:yX(e.clientId),status:e.activityState==="stale"?"offline":e.activityState==="idle"?"syncing":"online",cursor:e.cursor,actor:e.actorId,mode:e.connectionMode==="realtime"?"realtime":"polling",dialect:vX(e.clientId),scopes:Object.keys(e.effectiveScopes??{}),lastSeen:bX(e.updatedAt,n)}}function SX({emptyState:e}={}){const[t,n]=_.useState(1),[s,i]=_.useState(null),{preferences:a}=of(),{partitionId:l}=sf(),f=a.pageSize,d=a.refreshInterval*1e3,{data:p,isLoading:g}=rf({refetchIntervalMs:d,partitionId:l}),{data:y,isLoading:b,error:x}=pk({limit:f,offset:(t-1)*f,partitionId:l},{refetchIntervalMs:d}),S=RY(),w=Math.ceil((y?.total??0)/f),T=p?.maxCommitSeq??0;_.useEffect(()=>{n(1)},[]);const C=async()=>{if(s)try{await S.mutateAsync({clientId:s,partitionId:l})}finally{i(null)}};if(b||g)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});if(x)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger",children:["Failed to load clients: ",x.message]})});const O=(y?.items??[]).map(N=>xX(N,T,a.timeFormat));return h.jsxs("div",{className:"flex flex-col gap-5 px-5 py-5",children:[O.length>0&&h.jsx(Wj,{clients:O,headSeq:T}),O.length===0?e??h.jsx(F8,{children:h.jsx(Qb,{message:"No clients yet"})}):h.jsx(Vj,{clients:O,headSeq:T,onEvict:N=>{const R=y?.items.find(M=>M.clientId===N);i(R?.clientId??N)}}),w>1&&h.jsx(px,{page:t,totalPages:w,totalItems:y?.total??0,onPageChange:n}),h.jsx($r,{open:s!==null,onOpenChange:()=>i(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Evict Client"})}),h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs("p",{className:"font-mono text-[11px] text-neutral-300",children:["Are you sure you want to evict client"," ",h.jsxs("span",{className:"font-mono text-white",children:[s?.slice(0,12),"..."]}),"?"]}),h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"This will force the client to re-bootstrap on their next sync."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>i(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:C,disabled:S.isPending,children:S.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Evicting..."]}):"Evict"})]})]})})]})}const _X={latencyThresholdMs:1e3,errorRateThreshold:5,clientLagThreshold:50,enabled:!1};function wX(e){return e<1e3?`${e}ms`:e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function EX(e){const t=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);return Array.from(new Set(t))}function TX(e){switch(e){case"notify_data_change":return"Notify";case"evict_client":return"Evict";case"compact":return"Compact";default:return"Prune"}}function YC(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function CX(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function RX(e){const t=YC(e.requestPayload),n=YC(e.resultPayload);if(e.operationType==="notify_data_change"){const a=CX(t?.tables),l=n?.commitSeq;return`${a.length} table${a.length===1?"":"s"} -> commit #${typeof l=="number"?l:"?"}`}if(e.operationType==="evict_client"){const a=n?.evicted===!0?"evicted":"not found";return`client ${e.targetClientId??"?"} ${a}`}if(e.operationType==="compact")return`${typeof n?.deletedChanges=="number"?n.deletedChanges:0} changes removed`;const s=typeof n?.deletedCommits=="number"?n.deletedCommits:0,i=typeof t?.watermarkCommitSeq=="number"?` at #${t.watermarkCommitSeq}`:"";return`${s} commits removed${i}`}function NX(e){const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function jX(){const{partitionId:e}=sf();return h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-5",children:[h.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[h.jsx(AX,{}),h.jsx(PX,{})]}),h.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[h.jsx(kX,{partitionId:e}),h.jsx(OX,{partitionId:e}),h.jsx(MX,{partitionId:e})]}),h.jsx(IX,{partitionId:e})]})}function AX(){const{data:e,isLoading:t,error:n}=EY();if(t)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});if(n)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger",children:["Failed to load handlers: ",n.message]})});const s=(e?.items??[]).map(i=>({table:i.table,dependsOn:i.dependsOn?.join(", ")??null,chunkTtl:i.snapshotChunkTtlMs?wX(i.snapshotChunkTtlMs):"default"}));return h.jsx(Gj,{handlers:s,tableCount:e?.items.length??0})}function kX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState(null),{data:a,isLoading:l}=rf({partitionId:e}),{data:f,isLoading:d,refetch:p}=TY({enabled:!1}),g=NY(),y=async()=>{n(!0),i(null),await p()},b=async()=>{const S=await g.mutateAsync();i(S.deletedCommits)};if(l)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});const x=[{label:"Total commits",value:a?.commitCount??0},{label:"Commit range",value:`${a?.minCommitSeq??0} - ${a?.maxCommitSeq??0}`},{label:"Min active cursor",value:a?.minActiveClientCursor??"N/A",tone:"syncing"}];return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Prune",description:"Delete commits that all clients have already synced. Pruning removes commits older than the oldest active client cursor.",dotColor:"syncing",stats:x,actionLabel:"Preview Prune",actionVariant:"destructive",onAction:y}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Prune Old Commits"})}),h.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:s!==null?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Pruning Complete"}),h.jsxs(Pn,{children:["Successfully deleted ",h.jsx("strong",{children:s})," commits."]})]}):d?h.jsx("div",{className:"flex items-center justify-center py-8",children:h.jsx(Pt,{size:"sm"})}):f?h.jsxs(h.Fragment,{children:[h.jsx(In,{variant:f.commitsToDelete>0?"destructive":"default",children:h.jsx(Pn,{children:f.commitsToDelete>0?h.jsxs(h.Fragment,{children:["This will delete"," ",h.jsx("strong",{children:f.commitsToDelete})," commits up to sequence"," ",h.jsxs("code",{className:"font-mono",children:["#",f.watermarkCommitSeq]}),"."]}):"No commits are eligible for pruning."})}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex justify-between font-mono text-[11px]",children:[h.jsx("span",{className:"text-neutral-500",children:"Watermark commit seq:"}),h.jsxs("span",{className:"text-white",children:["#",f.watermarkCommitSeq]})]}),h.jsxs("div",{className:"flex justify-between font-mono text-[11px] items-center",children:[h.jsx("span",{className:"text-neutral-500",children:"Commits to delete:"}),h.jsx(mn,{variant:f.commitsToDelete>0?"offline":"ghost",children:f.commitsToDelete})]})]})]}):null}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:s!==null?"Close":"Cancel"}),s===null&&h.jsx(Ne,{variant:"destructive",onClick:b,disabled:g.isPending||d||(f?.commitsToDelete??0)===0,children:g.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Pruning..."]}):"Prune Now"})]})]})})]})}function OX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState(null),{data:a,isLoading:l}=rf({partitionId:e}),f=jY(),d=()=>{n(!0),i(null)},p=async()=>{const y=await f.mutateAsync();i(y.deletedChanges)};if(l)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});const g=[{label:"Total changes",value:a?.changeCount??0},{label:"Total commits",value:a?.commitCount??0}];return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Compact",description:"Merge old changes to reduce storage space. Compaction merges multiple changes to the same row into a single change.",dotColor:"flow",stats:g,actionLabel:"Run Compaction",actionVariant:"primary",onAction:d}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Compact Changes"})}),h.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:s!==null?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Compaction Complete"}),h.jsxs(Pn,{children:["Successfully removed ",h.jsx("strong",{children:s})," redundant changes."]})]}):h.jsx(In,{variant:"default",children:h.jsx(Pn,{children:"Compaction will merge multiple changes to the same row, keeping only the most recent version. This is safe and can be run at any time."})})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:s!==null?"Close":"Cancel"}),s===null&&h.jsx(Ne,{variant:"primary",onClick:p,disabled:f.isPending,children:f.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Compacting..."]}):"Compact Now"})]})]})})]})}function MX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState("tasks"),[a,l]=_.useState(e??""),[f,d]=_.useState(null),[p,g]=_.useState(null),y=AY(),b=EX(s),x=[{label:"Next tables",value:b.length,tone:"syncing"},{label:"Last commit seq",value:f?`#${f.commitSeq}`:"—",tone:"syncing"},{label:"Last chunks cleared",value:f?.deletedChunks??"—"}],S=()=>{n(!0),g(null)},w=async()=>{if(b.length===0){g("Provide at least one table name.");return}g(null);const T=await y.mutateAsync({tables:b,partitionId:a.trim()||void 0});d(T)};return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Notify Data Change",description:"Create a synthetic commit after external imports or direct DB writes so clients re-bootstrap for affected tables.",dotColor:"healthy",stats:x,actionLabel:"Notify Clients",actionVariant:"primary",onAction:S}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Notify External Data Change"})}),h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-4",children:[f?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Notification Sent"}),h.jsxs(Pn,{children:["Created synthetic commit"," ",h.jsxs("strong",{children:["#",f.commitSeq]})," for"," ",h.jsx("strong",{children:f.tables.length})," table",f.tables.length===1?"":"s"," and cleared"," ",h.jsx("strong",{children:f.deletedChunks})," cached chunk",f.deletedChunks===1?"":"s","."]})]}):h.jsx(In,{variant:"default",children:h.jsx(Pn,{children:"Use this when data changed outside Syncular push flow. It invalidates cached snapshot chunks and forces clients to pull fresh data."})}),p?h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:p})}):null,h.jsxs(ps,{children:[h.jsx(es,{children:"Tables (comma-separated)"}),h.jsx(Kn,{value:s,onChange:T=>i(T.target.value),placeholder:"tasks, notes",disabled:y.isPending}),h.jsx(pc,{children:"Enter one or more table names affected by the external change."})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Partition ID (optional)"}),h.jsx(Kn,{value:a,onChange:T=>l(T.target.value),placeholder:"default",disabled:y.isPending})]})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:f?"Close":"Cancel"}),f?null:h.jsx(Ne,{variant:"primary",onClick:w,disabled:y.isPending,children:y.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Notifying..."]}):"Notify Data Change"})]})]})})]})}function IX({partitionId:e}){const[t,n]=_.useState("all"),{data:s,isLoading:i,error:a}=CY({limit:20,offset:0,operationType:t==="all"?void 0:t,partitionId:e},{refetchIntervalMs:5e3});return h.jsx(Wb,{title:"Operation Audit",description:"Recent prune/compact/notify/evict actions with actor and result context.",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Ne,{variant:t==="all"?"default":"ghost",size:"sm",onClick:()=>n("all"),children:"All"}),h.jsx(Ne,{variant:t==="prune"?"default":"ghost",size:"sm",onClick:()=>n("prune"),children:"Prune"}),h.jsx(Ne,{variant:t==="compact"?"default":"ghost",size:"sm",onClick:()=>n("compact"),children:"Compact"}),h.jsx(Ne,{variant:t==="notify_data_change"?"default":"ghost",size:"sm",onClick:()=>n("notify_data_change"),children:"Notify"}),h.jsx(Ne,{variant:t==="evict_client"?"default":"ghost",size:"sm",onClick:()=>n("evict_client"),children:"Evict"})]}),contentClassName:"pt-2",children:i?h.jsx("div",{className:"flex items-center justify-center py-10",children:h.jsx(Pt,{size:"lg"})}):a?h.jsx(In,{variant:"destructive",children:h.jsxs(Pn,{children:["Failed to load operation audit events: ",a.message]})}):(s?.items.length??0)===0?h.jsx("div",{className:"px-2 py-8 text-sm text-neutral-500",children:"No operation events found for this filter."}):h.jsx("div",{className:"overflow-x-auto",children:h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:"Time"}),h.jsx(yt,{children:"Type"}),h.jsx(yt,{children:"User"}),h.jsx(yt,{children:"Target"}),h.jsx(yt,{children:"Result"})]})}),h.jsx(Xu,{children:(s?.items??[]).map((l,f)=>h.jsxs(io,{children:[h.jsx(vt,{className:"whitespace-nowrap text-xs text-neutral-400",children:NX(l.createdAt)}),h.jsx(vt,{children:h.jsx(mn,{variant:"ghost",children:TX(l.operationType)})}),h.jsx(vt,{className:"font-mono text-xs",children:l.consoleUserId??"system"}),h.jsx(vt,{className:"font-mono text-xs",children:l.targetClientId??l.partitionId??(l.operationType==="notify_data_change"?"partition default":"global")}),h.jsx(vt,{className:"font-mono text-xs text-neutral-300",children:RX(l)})]},`${l.operationId}:${l.createdAt}:${f}`))})]})})})}function PX(){const[e,t]=pi("console:alert-config",_X),n={p90Latency:e.latencyThresholdMs,errorRate:e.errorRateThreshold,clientLag:e.clientLagThreshold},s=a=>{t(l=>({...l,latencyThresholdMs:a.p90Latency,errorRateThreshold:a.errorRate,clientLagThreshold:a.clientLag}))},i=a=>{t(l=>({...l,enabled:a}))};return h.jsx(Uj,{enabled:e.enabled,onEnabledChange:i,thresholds:n,onThresholdsChange:s})}function DX(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n===0?0:1)} ${t[n]}`}function zX(e){const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function LX(){const[e,t]=_.useState(""),[n,s]=_.useState(void 0),[i,a]=_.useState(void 0),[l,f]=_.useState([]),[d,p]=_.useState(null),{data:g,isLoading:y,error:b}=zY({prefix:n,cursor:i,limit:100}),x=LY(),S=UY();function w(){const M=e.trim();s(M.length>0?M:void 0),a(void 0),f([])}function T(){t(""),s(void 0),a(void 0),f([])}function C(){g?.cursor&&(f(M=>[...M,i??""]),a(g.cursor))}function O(){f(M=>{const z=[...M],j=z.pop();return a(j&&j.length>0?j:void 0),z})}function N(){d&&x.mutate(d,{onSuccess:()=>p(null)})}if(y)return h.jsx("div",{className:"flex flex-col gap-4 px-5 py-5",children:h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})})});if(b)return h.jsx("div",{className:"flex flex-col gap-4 px-5 py-5",children:h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger font-mono text-[11px]",children:["Failed to load storage items: ",b.message]})})});const R=g?.items??[];return h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-5",children:[h.jsx(Wb,{title:"Storage",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Kn,{placeholder:"Prefix filter...",value:e,onChange:M=>t(M.target.value),onKeyDown:M=>{M.key==="Enter"&&w()},className:"h-7 w-48 text-xs"}),h.jsx(Ne,{variant:"default",size:"sm",onClick:w,children:"Filter"}),n&&h.jsx(Ne,{variant:"ghost",size:"sm",onClick:T,children:"Clear"})]}),children:R.length===0?h.jsx(Qb,{message:n?`No storage items matching prefix "${n}".`:"No storage items found."}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"overflow-x-auto",children:h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:"Key"}),h.jsx(yt,{children:"Size"}),h.jsx(yt,{children:"Type"}),h.jsx(yt,{children:"Uploaded"}),h.jsx(yt,{children:"Actions"})]})}),h.jsx(Xu,{children:R.map(M=>h.jsxs(io,{children:[h.jsx(vt,{className:"font-mono text-xs max-w-[320px]",title:M.key,children:M.key}),h.jsx(vt,{className:"font-mono text-xs text-neutral-400 whitespace-nowrap",children:DX(M.size)}),h.jsx(vt,{children:M.httpMetadata?.contentType?h.jsx(mn,{variant:"ghost",children:M.httpMetadata.contentType}):h.jsx("span",{className:"text-neutral-500 text-xs",children:"--"})}),h.jsx(vt,{className:"whitespace-nowrap text-xs text-neutral-400",children:zX(M.uploaded)}),h.jsx(vt,{children:h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>{S(M.key)},children:"Download"}),h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>p(M.key),children:"Delete"})]})})]},M.key))})]})}),h.jsxs("div",{className:"flex items-center justify-between px-2 py-2",children:[h.jsx(Ne,{variant:"ghost",size:"sm",disabled:l.length===0,onClick:O,children:"Previous"}),h.jsx(Ne,{variant:"ghost",size:"sm",disabled:!g?.truncated,onClick:C,children:"Next"})]})]})}),h.jsx($r,{open:d!==null,onOpenChange:()=>p(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Delete Storage Item"})}),h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs("p",{className:"font-mono text-[11px] text-neutral-300",children:["Are you sure you want to delete"," ",h.jsx("span",{className:"font-mono text-white",children:d}),"?"]}),h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"This action cannot be undone."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>p(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:N,disabled:x.isPending,children:x.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"})," Deleting..."]}):"Delete"})]})]})})]})}const UX={};function su(e,t){if(t==="absolute")return new Date(e).toLocaleString();const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3);return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m`:a<86400?`${Math.floor(a/3600)}h`:`${Math.floor(a/86400)}d`}function $X(e){const t=e.split(/\s+/).map(i=>i.trim()).filter(i=>i.length>0),n={},s=[];for(const i of t){const[a="",...l]=i.split(":"),f=l.join(":").trim(),d=a.toLowerCase();if(!f){s.push(i);continue}if(d==="actor"){n.actorId=f;continue}if(d==="client"){n.clientId=f;continue}if(d==="table"){n.table=f;continue}if(d==="request"){n.requestId=f;continue}if(d==="trace"){n.traceId=f;continue}s.push(i)}return s.length>0&&(n.search=s.join(" ")),n}function BX(e){return e==="1h"?3600*1e3:e==="6h"?360*60*1e3:e==="24h"?1440*60*1e3:e==="7d"?10080*60*1e3:720*60*60*1e3}function Kd(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function FX(e,t){return e?`#${e.federatedCommitId??(t?`${t}:${e.commitSeq}`:String(e.commitSeq))}`:"#?"}function HX(e,t){return e?`E${e.federatedEventId??(t?`${t}:${e.eventId}`:e.eventId)}`:"E?"}function qX(e,t,n){return!e||!t?null:e.replaceAll("{traceId}",encodeURIComponent(t)).replaceAll("{spanId}",encodeURIComponent(n??""))}function yx({initialSelectedEntryId:e}={}){const{preferences:t}=of(),{partitionId:n}=sf(),{range:s,setRange:i}=mk(),a=t.pageSize,l=t.refreshInterval*1e3,f=UX?.VITE_CONSOLE_TRACE_URL_TEMPLATE,[d,p]=_.useState(()=>e?.startsWith("#")?"commits":e?.startsWith("E")?"events":"all"),[g,y]=_.useState("all"),[b,x]=_.useState("all"),[S,w]=_.useState(""),[T,C]=_.useState(1),[O,N]=_.useState(!1),[R,M]=_.useState(e??null),z=_.useRef(!1),j=_.useMemo(()=>$X(S),[S]),A=_.useMemo(()=>new Date(Date.now()-BX(s)).toISOString(),[s]),{data:P,isLoading:Q,refetch:B}=SY({limit:a,offset:(T-1)*a,...n?{partitionId:n}:{},view:d,...d!=="commits"&&g!=="all"?{eventType:g}:{},...d!=="commits"&&b!=="all"?{outcome:b}:{},...j.actorId?{actorId:j.actorId}:{},...j.clientId?{clientId:j.clientId}:{},...j.requestId?{requestId:j.requestId}:{},...j.traceId?{traceId:j.traceId}:{},...j.table?{table:j.table}:{},...j.search?{search:j.search}:{},from:A},{refetchIntervalMs:l}),U=XY(),Z=R?.startsWith("#")?R.slice(1):void 0,G=R?.startsWith("E")?R.slice(1):void 0,ee=Z&&Z!=="?"?Z:void 0,D=G&&G!=="?"?G:void 0,{data:K,isLoading:q,error:V}=xY(ee,{enabled:ee!==void 0,partitionId:n}),{data:L,isLoading:I,error:H}=_Y(D,{enabled:D!==void 0,partitionId:n}),{data:W,isLoading:Y,error:ae}=wY(D,{enabled:D!==void 0&&!!L?.payloadRef,partitionId:n}),se=_.useMemo(()=>qX(f,L?.traceId??null,L?.spanId??null),[L?.spanId,L?.traceId,f]);_.useEffect(()=>{C(1)},[]),_.useEffect(()=>{C(1)},[]),_.useEffect(()=>{e&&M(e)},[e]),_.useEffect(()=>{if(!z.current){z.current=!0;return}M(null)},[]),_.useEffect(()=>{C(1),M(null)},[]);const Se=_.useMemo(()=>(P?.items??[]).map(we=>{const ye=we.instanceId??we.commit?.instanceId??we.event?.instanceId,xe=ye?`[${ye}] `:"";if(we.type==="commit"&&we.commit){const Ie=we.commit;return{type:"commit",id:FX(Ie,ye),outcome:"--",duration:"--",actor:Ie.actorId,client:Ie.clientId,detail:`${xe}${Ie.changeCount} chg | ${(Ie.affectedTables??[]).join(", ")}`,time:su(we.timestamp,t.timeFormat)}}const ve=we.event;return ve?{type:ve.eventType,id:HX(ve,ye),outcome:ve.outcome,duration:`${ve.durationMs}ms`,actor:ve.actorId,client:ve.clientId,detail:`${xe}${(ve.tables??[]).join(", ")||"--"}`,time:su(we.timestamp,t.timeFormat)}:{type:"pull",id:"E?",outcome:"unknown",duration:"--",actor:"",client:"",detail:"--",time:su(we.timestamp,t.timeFormat)}}),[t.timeFormat,P?.items]),pe=P?.total??0,Me=Math.max(1,Math.ceil(pe/a)),_e=Q,re=[{label:"",options:[{id:"all",label:"All"},{id:"commits",label:"Commits"},{id:"events",label:"Events"}],activeId:d,onActiveChange:ie=>{p(ie),ie==="commits"&&(y("all"),x("all")),C(1)}},{label:"Time",options:[{id:"1h",label:"1h"},{id:"6h",label:"6h"},{id:"24h",label:"24h"},{id:"7d",label:"7d"},{id:"30d",label:"30d"}],activeId:s,onActiveChange:ie=>{i(ie),C(1)}},{label:"Type",options:[{id:"all",label:"All"},{id:"push",label:"Push"},{id:"pull",label:"Pull"}],activeId:g,onActiveChange:ie=>{y(ie),C(1)}},{label:"Outcome",options:[{id:"all",label:"All"},{id:"applied",label:"Applied"},{id:"error",label:"Error"},{id:"rejected",label:"Rejected"}],activeId:b,onActiveChange:ie=>{x(ie),C(1)}}];function he(){U.mutate(void 0,{onSuccess:()=>{N(!1),B()}})}return h.jsxs("div",{className:"flex flex-col h-full",children:[_e&&Se.length===0?h.jsx("div",{className:"flex items-center justify-center py-24",children:h.jsx(Pt,{size:"lg"})}):h.jsx(Qj,{entries:Se,selectedEntryId:R,onEntryClick:ie=>M(ie.id),filterBar:h.jsx(qj,{groups:re,searchValue:S,searchPlaceholder:"Use actor:, client:, table:, request:, trace: or free text...",onSearchChange:w,actions:h.jsxs(h.Fragment,{children:[h.jsx(Ne,{size:"sm",variant:"ghost",onClick:()=>{B()},children:"Refresh"}),h.jsx(Ne,{size:"sm",variant:"ghost",children:"Export"}),h.jsx(Ne,{size:"sm",variant:"destructive",onClick:()=>N(!0),children:"Clear"})]})}),pagination:h.jsx(px,{page:T,totalPages:Me,totalItems:pe,onPageChange:C})}),h.jsx($r,{open:R!==null,onOpenChange:ie=>{ie||M(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:ee!==void 0?`Commit #${ee}`:D!==void 0?`Event E${D}`:"Entry details"})}),h.jsx("div",{className:"px-5 py-4 space-y-3 max-h-[70vh] overflow-y-auto",children:q||I?h.jsx("div",{className:"flex items-center justify-center py-8",children:h.jsx(Pt,{size:"sm"})}):V||H?h.jsx("p",{className:"font-mono text-[11px] text-offline",children:"Failed to load details."}):K?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"grid grid-cols-2 gap-3 font-mono text-[11px]",children:[h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Actor"}),h.jsx("div",{className:"text-neutral-100",children:K.actorId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Client"}),h.jsx("div",{className:"text-neutral-100",children:K.clientId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Instance"}),h.jsx("div",{className:"text-neutral-100",children:K.instanceId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Created"}),h.jsx("div",{className:"text-neutral-100",children:su(K.createdAt,t.timeFormat)})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Changes"}),h.jsx("div",{className:"text-neutral-100",children:K.changeCount})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Affected Tables"}),h.jsx("p",{className:"font-mono text-[11px] text-neutral-200",children:K.affectedTables.join(", ")||"--"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Changes"}),K.changes.length===0?h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No changes recorded."}):K.changes.map(ie=>h.jsxs("div",{className:"rounded-md border border-border p-3 space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between font-mono text-[11px]",children:[h.jsxs("span",{className:"text-neutral-300",children:[ie.table," | ",ie.op]}),h.jsxs("span",{className:"text-neutral-500",children:["#",ie.changeId]})]}),h.jsxs("div",{className:"font-mono text-[11px] text-neutral-400",children:["rowId: ",ie.rowId,ie.rowVersion!==null?` | version: ${ie.rowVersion}`:""]}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(ie.rowJson)})]},ie.changeId))]})]}):L?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"grid grid-cols-2 gap-3 font-mono text-[11px]",children:[h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Type"}),h.jsx("div",{className:"text-neutral-100",children:L.eventType})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Path"}),h.jsx("div",{className:"text-neutral-100",children:L.syncPath})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Instance"}),h.jsx("div",{className:"text-neutral-100",children:L.instanceId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Outcome"}),h.jsx("div",{className:"text-neutral-100",children:L.outcome})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Response Status"}),h.jsx("div",{className:"text-neutral-100",children:L.responseStatus})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Actor"}),h.jsx("div",{className:"text-neutral-100",children:L.actorId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Client"}),h.jsx("div",{className:"text-neutral-100",children:L.clientId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Status"}),h.jsx("div",{className:"text-neutral-100",children:L.statusCode})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Transport"}),h.jsx("div",{className:"text-neutral-100",children:L.transportPath})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Duration"}),h.jsxs("div",{className:"text-neutral-100",children:[L.durationMs,"ms"]})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Request ID"}),h.jsx("div",{className:"text-neutral-100",children:L.requestId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Trace ID"}),h.jsx("div",{className:"text-neutral-100",children:L.traceId??"--"}),se&&h.jsx("a",{href:se,target:"_blank",rel:"noreferrer",className:"font-mono text-[10px] text-flow underline underline-offset-4",children:"Open external trace"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Span ID"}),h.jsx("div",{className:"text-neutral-100",children:L.spanId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Commit Seq"}),h.jsx("div",{className:"text-neutral-100",children:L.commitSeq??"--"}),L.commitSeq!==null&&h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>M(`#${L.instanceId?`${L.instanceId}:`:""}${L.commitSeq}`),children:"Open linked commit"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Subscription Count"}),h.jsx("div",{className:"text-neutral-100",children:L.subscriptionCount??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Error Code"}),h.jsx("div",{className:"text-neutral-100",children:L.errorCode??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Payload Ref"}),h.jsx("div",{className:"text-neutral-100",children:L.payloadRef??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Created"}),h.jsx("div",{className:"text-neutral-100",children:su(L.createdAt,t.timeFormat)})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Tables"}),h.jsx("p",{className:"font-mono text-[11px] text-neutral-200",children:L.tables.join(", ")||"--"})]}),L.scopesSummary&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Scopes Summary"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(L.scopesSummary)})]}),L.payloadRef&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Payload Snapshot"}),Y?h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Pt,{size:"sm"}),h.jsx("span",{className:"font-mono text-[11px] text-neutral-400",children:"Loading payload snapshot..."})]}):ae?h.jsx("p",{className:"font-mono text-[11px] text-offline",children:"Failed to load payload snapshot."}):W?h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Request"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(W.requestPayload)}),h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Response"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(W.responsePayload)})]}):h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No payload snapshot available."})]}),L.errorMessage&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Error"}),h.jsx("p",{className:"font-mono text-[11px] text-offline",children:L.errorMessage})]})]}):h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No details available for this row."})}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>M(null),children:"Close"})})]})}),h.jsx($r,{open:O,onOpenChange:ie=>{ie||N(!1)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Clear all events"})}),h.jsx("div",{className:"p-4",children:h.jsx("span",{className:"font-mono text-[11px] text-neutral-400",children:"This will permanently delete all request events. Commits are not affected. Are you sure?"})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>N(!1),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",size:"sm",onClick:he,disabled:U.isPending,children:U.isPending?"Clearing...":"Clear all"})]})]})})]})}const VX=co({getParentRoute:()=>uo,path:"/config",component:lX}),GX=co({getParentRoute:()=>uo,path:"/fleet",component:SX}),KX=co({getParentRoute:()=>uo,path:"/",component:cX});function ZX(){const{seq:e}=gk.useParams();return h.jsx(yx,{initialSelectedEntryId:`#${e}`})}const gk=co({getParentRoute:()=>uo,path:"/investigate/commit/$seq",component:ZX});function YX(){const{id:e}=yk.useParams();return h.jsx(yx,{initialSelectedEntryId:`E${e}`})}const yk=co({getParentRoute:()=>uo,path:"/investigate/event/$id",component:YX}),XX=co({getParentRoute:()=>uo,path:"/ops",component:jX}),QX=co({getParentRoute:()=>uo,path:"/storage",component:LX}),WX=co({getParentRoute:()=>uo,path:"/stream",component:yx}),JX=uo.addChildren([KX,WX,gk,yk,GX,XX,QX,VX]),eQ="syncular-console-basepath",tQ="syncular-console-server-url",nQ="syncular-console-token";function rQ(e){if(!e)return;const t=e.trim();return t.length>0?t:void 0}function $v(e){const t=globalThis.document;if(!t)return;const n=t.querySelector(`meta[name="${e}"]`)?.getAttribute("content");return rQ(n)}function vk(e){return!e||e==="/"?"/":(e.startsWith("/")?e:`/${e}`).replace(/\/+$/g,"")||"/"}function sQ(){return vk($v(eQ))}function oQ(){const e=$v(tQ),t=$v(nQ);return!e||!t?null:{serverUrl:e,token:t}}function iQ(){return new k6({defaultOptions:{queries:{staleTime:5e3,retry:1}}})}function aQ(e){return vk(e??sQ())}function cQ(e){const[t]=_.useState(()=>iQ()),n=_.useMemo(()=>DH({routeTree:JX,basepath:aQ(e.basePath)}),[e.basePath]),s=e.defaultConfig===void 0?oQ():e.defaultConfig;return h.jsx(O6,{client:t,children:h.jsx(WH,{defaultConfig:s,children:h.jsx(UH,{router:n})})})}function lQ(e){return h.jsx("div",{className:gx,children:h.jsx(cQ,{...e})})}function uQ(e){const t=document.querySelector(e);if(!t)throw new Error(`Unable to mount console: ${e} not found`);return t}function fQ(e,t={}){const n=uQ(e);HY(n);const s=a6.createRoot(n),i=h.jsx(lQ,{basePath:t.basePath,defaultConfig:t.defaultConfig});return t.strictMode===!1?(s.render(i),s):(s.render(h.jsx(_.StrictMode,{children:i})),s)}var dQ={};const hQ="syncular-sentry-dsn",pQ="syncular-sentry-environment",mQ="syncular-sentry-release";function hu(e){if(!e)return;const t=e.trim();return t.length>0?t:void 0}function By(e){if(typeof document>"u")return;const t=document.querySelector(`meta[name="${e}"]`)?.getAttribute("content");return hu(t)}function Fy(e){if(!(typeof process>"u"))return hu(dQ[e])}function Hy(e){for(const t of e)if(t)return t}function gQ(){const e=Hy([hu(globalThis.__SYNCULAR_SENTRY_DSN__),By(hQ),Fy("SYNCULAR_SENTRY_DSN")]);if(!e)return null;const t=Hy([hu(globalThis.__SYNCULAR_SENTRY_ENVIRONMENT__),By(pQ),Fy("SYNCULAR_SENTRY_ENVIRONMENT")]),n=Hy([hu(globalThis.__SYNCULAR_SENTRY_RELEASE__),By(mQ),Fy("SYNCULAR_SENTRY_RELEASE")]);return{dsn:e,environment:t,release:n,enableLogs:!0,tracesSampleRate:.2,tracePropagationTargets:[/^https?:\/\/.*\/api\/.*/]}}const XC=gQ();XC&&WB(XC);fQ("#root");
86
+ )`}return h.jsx("div",{ref:n,role:"presentation","data-base-ui-inert":"",...i,style:{position:"fixed",inset:0,userSelect:"none",WebkitUserSelect:"none",clipPath:a}})});function Qh(e,t){e&&Object.assign(e.style,t)}const OK={position:"relative",maxHeight:"100%",overflowX:"hidden",overflowY:"auto"},MK={position:"fixed"},IK=_.forwardRef(function(t,n){const{anchor:s,positionMethod:i="absolute",className:a,render:l,side:f="bottom",align:d="center",sideOffset:p=0,alignOffset:g=0,collisionBoundary:y="clipping-ancestors",collisionPadding:b,arrowPadding:x=5,sticky:S=!1,disableAnchorTracking:w,alignItemWithTrigger:T=!0,collisionAvoidance:C=Y9,...O}=t,{store:N,listRef:R,labelsRef:M,alignItemWithTriggerActiveRef:z,selectedItemTextRef:j,valuesRef:A,initialValueRef:P,popupRef:Q,setValue:B}=Wu(),U=$A(),Z=at(N,it.open),G=at(N,it.mounted),ee=at(N,it.modal),D=at(N,it.value),K=at(N,it.openMethod),q=at(N,it.positionerElement),V=at(N,it.triggerElement),L=at(N,it.isItemEqualToValue),I=at(N,it.transitionStatus),H=_.useRef(null),W=_.useRef(null),[Y,ae]=_.useState(T),se=G&&Y&&K!=="touch";!G&&Y!==T&&ae(T),Le(()=>{G||(it.scrollUpArrowVisible(N.state)&&N.set("scrollUpArrowVisible",!1),it.scrollDownArrowVisible(N.state)&&N.set("scrollDownArrowVisible",!1))},[N,G]),_.useImperativeHandle(z,()=>se),BA((se||ee)&&Z&&K!=="touch",V);const fe=DA({anchor:s,floatingRootContext:U,positionMethod:i,mounted:G,side:f,sideOffset:p,align:d,alignOffset:g,arrowPadding:x,collisionBoundary:y,collisionPadding:b,sticky:S,disableAnchorTracking:w??se,collisionAvoidance:C,keepMounted:!0}),Se=se?"none":fe.side,pe=se?MK:fe.positionerStyles,Me=_.useMemo(()=>{const xe={};return Z||(xe.pointerEvents="none"),{role:"presentation",hidden:!G,style:{...pe,...xe}}},[Z,G,pe]),_e={open:Z,side:Se,align:fe.align,anchorHidden:fe.anchorHidden},re=ke(xe=>{N.set("positionerElement",xe)}),he=zt("div",t,{ref:[n,re],state:_e,stateAttributesMapping:nl,props:[Me,Np(I),O]}),ie=_.useRef(0),we=ke(xe=>{if(xe.size===0&&ie.current===0||A.current.length===0)return;const ve=ie.current;if(ie.current=xe.size,xe.size===ve)return;const Ie=Yt(ii);if(ve!==0&&!N.state.multiple&&D!==null&&zy(A.current,D,L)===-1){const Ee=P.current,Qe=Ee!=null&&zy(A.current,Ee,L)!==-1?Ee:null;B(Qe,Ie),Qe===null&&(N.set("selectedIndex",null),j.current=null)}if(ve!==0&&N.state.multiple&&Array.isArray(D)){const Ue=Ve=>zy(A.current,Ve,L)!==-1,Ee=D.filter(Ve=>Ue(Ve));(Ee.length!==D.length||Ee.some(Ve=>!cK(D,Ve,L)))&&(B(Ee,Ie),Ee.length===0&&(N.set("selectedIndex",null),j.current=null))}if(Z&&se){N.update({scrollUpArrowVisible:!1,scrollDownArrowVisible:!1});const Ue={height:""};Qh(q,Ue),Qh(Q.current,Ue)}}),ye=_.useMemo(()=>({...fe,side:Se,alignItemWithTriggerActive:se,setControlledAlignItemWithTrigger:ae,scrollUpArrowRef:H,scrollDownArrowRef:W}),[fe,Se,se,ae]);return h.jsx(HA,{elementsRef:R,labelsRef:M,onMapChange:we,children:h.jsxs(qA.Provider,{value:ye,children:[G&&ee&&h.jsx(VA,{inert:fx(!Z),cutout:V}),he]})})});function GA(e){const t=e.currentTarget.getBoundingClientRect();return t.top+1<=e.clientY&&e.clientY<=t.bottom-1&&t.left+1<=e.clientX&&e.clientX<=t.right-1}const Vd="base-ui-disable-scrollbar",PC={className:Vd,getElement(e){return h.jsx("style",{nonce:e,href:Vd,precedence:"base-ui:low",children:`.${Vd}{scrollbar-width:none}.${Vd}::-webkit-scrollbar{display:none}`})}},PK=_.createContext(void 0);function KA(e){return _.useContext(PK)}const wc="ArrowUp",Wi="ArrowDown",Ru="ArrowLeft",Ec="ArrowRight",Ju="Home",ef="End",ZA=new Set([Ru,Ec]),DK=new Set([Ru,Ec,Ju,ef]),YA=new Set([wc,Wi]),zK=new Set([wc,Wi,Ju,ef]),XA=new Set([...ZA,...YA]),LK=new Set([...XA,Ju,ef]),QA=new Set([wc,Wi,Ru,Ec,Ju,ef]),UK="Shift",$K="Control",BK="Alt",FK="Meta",HK=new Set([UK,$K,BK,FK]);function qK(e){return Zt(e)&&e.tagName==="INPUT"}function DC(e){return!!(qK(e)&&e.selectionStart!=null||Zt(e)&&e.tagName==="TEXTAREA")}function zC(e,t,n,s){if(!e||!t||!t.scrollTo)return;let i=e.scrollLeft,a=e.scrollTop;const l=e.clientWidth<e.scrollWidth,f=e.clientHeight<e.scrollHeight;if(l&&s!=="vertical"){const d=LC(e,t,"left"),p=Gd(e),g=Gd(t);n==="ltr"&&(d+t.offsetWidth+g.scrollMarginRight>e.scrollLeft+e.clientWidth-p.scrollPaddingRight?i=d+t.offsetWidth+g.scrollMarginRight-e.clientWidth+p.scrollPaddingRight:d-g.scrollMarginLeft<e.scrollLeft+p.scrollPaddingLeft&&(i=d-g.scrollMarginLeft-p.scrollPaddingLeft)),n==="rtl"&&(d-g.scrollMarginRight<e.scrollLeft+p.scrollPaddingLeft?i=d-g.scrollMarginLeft-p.scrollPaddingLeft:d+t.offsetWidth+g.scrollMarginRight>e.scrollLeft+e.clientWidth-p.scrollPaddingRight&&(i=d+t.offsetWidth+g.scrollMarginRight-e.clientWidth+p.scrollPaddingRight))}if(f&&s!=="horizontal"){const d=LC(e,t,"top"),p=Gd(e),g=Gd(t);d-g.scrollMarginTop<e.scrollTop+p.scrollPaddingTop?a=d-g.scrollMarginTop-p.scrollPaddingTop:d+t.offsetHeight+g.scrollMarginBottom>e.scrollTop+e.clientHeight-p.scrollPaddingBottom&&(a=d+t.offsetHeight+g.scrollMarginBottom-e.clientHeight+p.scrollPaddingBottom)}e.scrollTo({left:i,top:a,behavior:"auto"})}function LC(e,t,n){const s=n==="left"?"offsetLeft":"offsetTop";let i=0;for(;t.offsetParent&&(i+=t[s],t.offsetParent!==e);)t=t.offsetParent;return i}function Gd(e){const t=getComputedStyle(e);return{scrollMarginTop:parseFloat(t.scrollMarginTop)||0,scrollMarginRight:parseFloat(t.scrollMarginRight)||0,scrollMarginBottom:parseFloat(t.scrollMarginBottom)||0,scrollMarginLeft:parseFloat(t.scrollMarginLeft)||0,scrollPaddingTop:parseFloat(t.scrollPaddingTop)||0,scrollPaddingRight:parseFloat(t.scrollPaddingRight)||0,scrollPaddingBottom:parseFloat(t.scrollPaddingBottom)||0,scrollPaddingLeft:parseFloat(t.scrollPaddingLeft)||0}}function Ly(e,t=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,n))}const VK=_.createContext(void 0),GK={disableStyleElements:!1};function KK(){return _.useContext(VK)??GK}const Vi=1,ZK={...nl,...ba},YK=_.forwardRef(function(t,n){const{render:s,className:i,finalFocus:a,...l}=t,{store:f,popupRef:d,onOpenChangeComplete:p,setOpen:g,valueRef:y,selectedItemTextRef:b,keyboardActiveRef:x,multiple:S,handleScrollArrowVisibility:w,scrollHandlerRef:T,highlightItemOnHover:C}=Wu(),{side:O,align:N,alignItemWithTriggerActive:R,setControlledAlignItemWithTrigger:M,scrollDownArrowRef:z,scrollUpArrowRef:j}=kK(),A=KA()!=null,P=$A(),{nonce:Q,disableStyleElements:B}=KK(),U=ns(),Z=at(f,it.id),G=at(f,it.open),ee=at(f,it.mounted),D=at(f,it.popupProps),K=at(f,it.transitionStatus),q=at(f,it.triggerElement),V=at(f,it.positionerElement),L=at(f,it.listElement),I=_.useRef(0),H=_.useRef(!1),W=_.useRef(0),Y=_.useRef(!1),ae=_.useRef({}),se=ox(),fe=ke(_e=>{if(!V||!d.current||!Y.current)return;if(H.current||!R){w();return}const re=V.style.top==="0px",he=V.style.bottom==="0px",ie=V.getBoundingClientRect().height,we=Rt(V),ye=getComputedStyle(V),xe=parseFloat(ye.marginTop),ve=parseFloat(ye.marginBottom),Ie=UC(getComputedStyle(d.current)),Ue=Math.min(we.documentElement.clientHeight-xe-ve,Ie),Ee=_e.scrollTop,Ve=$C(_e);let Qe=0,Be=null,We=!1,He=!1;const me=qe=>{V.style.height=`${qe}px`},Te=(qe,ht)=>{const lt=Ly(qe,0,Ue-ie);lt>0&&me(ie+lt),_e.scrollTop=ht,Ue-(ie+lt)<=Vi&&(H.current=!0),w()};if(re){const qe=Ve-Ee,ht=ie+qe,lt=Math.min(ht,Ue);if(Qe=lt,qe<=Vi){Te(qe,Ve);return}Ue-lt>Vi?He=!0:We=!0}else if(he){const qe=Ee,ht=ie+qe,lt=Math.min(ht,Ue),wr=ht-Ue;if(Qe=lt,qe<=Vi){Te(qe,0);return}Ue-lt>Vi?Be=0:(We=!0,Ee<Ve&&(Be=Ee-(qe-wr)))}if(Qe=Math.ceil(Qe),Qe!==0&&me(Qe),He||Be!=null){const qe=$C(_e),ht=He?qe:Ly(Be,0,qe);Math.abs(_e.scrollTop-ht)>Vi&&(_e.scrollTop=ht)}(We||Qe>=Ue-Vi)&&(H.current=!0),w()});_.useImperativeHandle(T,()=>fe,[fe]),xa({open:G,ref:d,onComplete(){G&&p?.(!0)}});const Se={open:G,transitionStatus:K,side:O,align:N};Le(()=>{!V||!d.current||Object.keys(ae.current).length||(ae.current={top:V.style.top||"0",left:V.style.left||"0",right:V.style.right,height:V.style.height,bottom:V.style.bottom,minHeight:V.style.minHeight,maxHeight:V.style.maxHeight,marginTop:V.style.marginTop,marginBottom:V.style.marginBottom})},[d,V]),Le(()=>{G||R||(Y.current=!1,H.current=!1,I.current=0,W.current=0,Qh(V,ae.current))},[G,R,V,d]),Le(()=>{const _e=d.current;if(!(!G||!q||!V||!_e||f.state.transitionStatus==="ending")){if(!R){Y.current=!0,se.request(w),_e.style.removeProperty("--transform-origin");return}queueMicrotask(()=>{const re=XK(_e);_e.style.removeProperty("--transform-origin");try{const he=getComputedStyle(V),ie=getComputedStyle(_e),we=Rt(q),ye=un(V),xe=q.getBoundingClientRect(),ve=V.getBoundingClientRect(),Ie=xe.left,Ue=xe.height,Ee=L||_e,Ve=Ee.scrollHeight,Qe=parseFloat(ie.borderBottomWidth),Be=parseFloat(he.marginTop)||10,We=parseFloat(he.marginBottom)||10,He=parseFloat(he.minHeight)||100,me=UC(ie),Te=5,qe=5,ht=20,lt=we.documentElement.clientHeight-Be-We,wr=we.documentElement.clientWidth,Er=lt-xe.bottom+Ue,Qt=b.current,ut=y.current;let xt,ot=0,Wt=0;if(Qt&&ut){const tr=ut.getBoundingClientRect();xt=Qt.getBoundingClientRect();const cs=tr.left-Ie,fo=xt.left-ve.left,ho=tr.top-xe.top+tr.height/2,nr=xt.top-ve.top+xt.height/2;ot=cs-fo,Wt=nr-ho}const vn=Er+Wt+We+Qe;let kt=Math.min(lt,vn);const Cn=lt-Be-We,er=vn-kt,An=Math.max(Te,Ie+ot),is=wr-qe,as=Math.max(0,An+ve.width-is);V.style.left=`${An-as}px`,V.style.height=`${kt}px`,V.style.maxHeight="auto",V.style.marginTop=`${Be}px`,V.style.marginBottom=`${We}px`,_e.style.height="100%";const _a=Ee.scrollHeight-Ee.clientHeight,wi=er>=_a;wi&&(kt=Math.min(lt,ve.height)-(er-_a));const Ei=xe.top<ht||xe.bottom>lt-ht||kt<Math.min(Ve,He),_s=(ye.visualViewport?.scale??1)!==1&&tx;if(Ei||_s){Y.current=!0,Qh(V,ae.current),hi.flushSync(()=>M(!1));return}if(wi){const tr=Math.max(0,lt-vn);V.style.top=ve.height>=Cn?"0":`${tr}px`,V.style.height=`${kt}px`,Ee.scrollTop=Ee.scrollHeight-Ee.clientHeight,I.current=Math.max(He,kt)}else V.style.bottom="0",I.current=Math.max(He,kt),Ee.scrollTop=er;if(xt){const tr=ve.top,cs=ve.height,fo=xt.top+xt.height/2,ho=cs>0?(fo-tr)/cs*100:50,nr=Ly(ho,0,100);_e.style.setProperty("--transform-origin",`50% ${nr}%`)}(I.current===lt||kt>=me)&&(H.current=!0),w(),setTimeout(()=>{Y.current=!0})}finally{re()}})}},[f,G,V,q,y,b,d,w,R,M,se,z,j,L]),_.useEffect(()=>{if(!R||!V||!G)return;const _e=un(V);function re(he){g(!1,Yt(x8,he))}return _e.addEventListener("resize",re),()=>{_e.removeEventListener("resize",re)}},[g,R,V,G]);const pe={...L?{role:"presentation","aria-orientation":void 0}:{role:"listbox","aria-multiselectable":S||void 0,id:`${Z}-list`},onKeyDown(_e){x.current=!0,A&&QA.has(_e.key)&&_e.stopPropagation()},onMouseMove(){x.current=!1},onPointerLeave(_e){if(!C||GA(_e)||_e.pointerType==="touch")return;const re=_e.currentTarget;U.start(0,()=>{f.set("activeIndex",null),re.focus({preventScroll:!0})})},onScroll(_e){L||fe(_e.currentTarget)},...R&&{style:L?{height:"100%"}:OK}},Me=zt("div",t,{ref:[n,d],state:Se,stateAttributesMapping:ZK,props:[D,pe,Np(K),{className:!L&&R?PC.className:void 0},l]});return h.jsxs(_.Fragment,{children:[!B&&PC.getElement(Q),h.jsx(_A,{context:P,modal:!1,disabled:!ee,returnFocus:a,restoreFocus:!0,children:Me})]})});function UC(e){const t=e.maxHeight||"";return t.endsWith("px")&&parseFloat(t)||1/0}function $C(e){return Math.max(0,e.scrollHeight-e.clientHeight)}const BC=[["transform","none"],["scale","1"],["translate","0 0"]];function XK(e){const{style:t}=e,n={};for(const[s,i]of BC)n[s]=t.getPropertyValue(s),t.setProperty(s,i,"important");return()=>{for(const[s]of BC){const i=n[s];i?t.setProperty(s,i):t.removeProperty(s)}}}let WA=(function(e){return e[e.None=0]="None",e[e.GuessFromOrder=1]="GuessFromOrder",e})({});function dx(e={}){const{label:t,metadata:n,textRef:s,indexGuessBehavior:i,index:a}=e,{register:l,unregister:f,subscribeMapChange:d,elementsRef:p,labelsRef:g,nextIndexRef:y}=RK(),b=_.useRef(-1),[x,S]=_.useState(a??(i===WA.GuessFromOrder?()=>{if(b.current===-1){const C=y.current;y.current+=1,b.current=C}return b.current}:-1)),w=_.useRef(null),T=_.useCallback(C=>{if(w.current=C,x!==-1&&C!==null&&(p.current[x]=C,g)){const O=t!==void 0;g.current[x]=O?t:s?.current?.textContent??C.textContent}},[x,p,g,t,s]);return Le(()=>{if(a!=null)return;const C=w.current;if(C)return l(C,n),()=>{f(C)}},[a,l,f,n]),Le(()=>{if(a==null)return d(C=>{const O=w.current?C.get(w.current)?.index:null;O!=null&&S(O)})},[a,d,S]),_.useMemo(()=>({ref:T,index:x}),[x,T])}const QK=_.createContext(void 0),WK=_.memo(_.forwardRef(function(t,n){const{render:s,className:i,value:a=null,label:l,disabled:f=!1,nativeButton:d=!1,...p}=t,g=_.useRef(null),y=dx({label:l,textRef:g,indexGuessBehavior:WA.GuessFromOrder}),{store:b,getItemProps:x,setOpen:S,setValue:w,selectionRef:T,typingRef:C,valuesRef:O,keyboardActiveRef:N,multiple:R,highlightItemOnHover:M}=Wu(),z=ns(),j=at(b,it.isActive,y.index),A=at(b,it.isSelected,y.index,a),P=at(b,it.isSelectedByFocus,y.index),Q=at(b,it.isItemEqualToValue),B=y.index,U=B!==-1,Z=_.useRef(null),G=Jo(B);Le(()=>{if(!U)return;const se=O.current;return se[B]=a,()=>{delete se[B]}},[U,B,a,O]),Le(()=>{if(!U)return;const se=b.state.value;let fe=se;R&&Array.isArray(se)&&se.length>0&&(fe=se[se.length-1]),fe!==void 0&&$c(a,fe,Q)&&b.set("selectedIndex",B)},[U,B,R,Q,b,a]);const ee={disabled:f,selected:A,highlighted:j},D=x({active:j,selected:A});D.onFocus=void 0,D.id=void 0;const K=_.useRef(null),q=_.useRef("mouse"),V=_.useRef(!1),{getButtonProps:L,buttonRef:I}=Jc({disabled:f,focusableWhenDisabled:!0,native:d});function H(se){const fe=b.state.value;if(R){const Se=Array.isArray(fe)?fe:[],pe=A?lK(Se,a,Q):[...Se,a];w(pe,Yt(Cy,se))}else w(a,Yt(Cy,se)),S(!1,Yt(Cy,se))}const W={role:"option","aria-selected":A,tabIndex:j?0:-1,onFocus(){b.set("activeIndex",B)},onMouseEnter(){!N.current&&b.state.selectedIndex===null&&M&&b.set("activeIndex",B)},onMouseMove(){M&&b.set("activeIndex",B)},onMouseLeave(se){!M||N.current||GA(se)||z.start(0,()=>{b.state.activeIndex===B&&b.set("activeIndex",null)})},onTouchStart(){T.current={allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1}},onKeyDown(se){K.current=se.key,b.set("activeIndex",B)},onClick(se){V.current=!1,!(se.type==="keydown"&&K.current===null)&&(f||K.current===" "&&C.current||q.current!=="touch"&&!j||(K.current=null,H(se.nativeEvent)))},onPointerEnter(se){q.current=se.pointerType},onPointerDown(se){q.current=se.pointerType,V.current=!0},onMouseUp(se){if(f)return;if(V.current){V.current=!1;return}const fe=!T.current.allowSelectedMouseUp&&A,Se=!T.current.allowUnselectedMouseUp&&!A;fe||Se||q.current!=="touch"&&!j||H(se.nativeEvent)}},Y=zt("div",t,{ref:[I,n,y.ref,Z],state:ee,props:[D,W,p,L]}),ae=_.useMemo(()=>({selected:A,indexRef:G,textRef:g,selectedByFocus:P,hasRegistered:U}),[A,G,g,P,U]);return h.jsx(QK.Provider,{value:ae,children:Y})})),JK=_.forwardRef(({className:e,children:t,...n},s)=>h.jsx(vK,{ref:s,className:ge("inline-flex items-center justify-between bg-surface border border-border rounded-md px-3 py-1.5 font-mono text-[12px] text-foreground cursor-pointer hover:border-border-bright transition",e),...n,children:t}));JK.displayName="SelectTrigger";const eZ=_.forwardRef(({className:e,portalProps:t,positionerProps:n,...s},i)=>h.jsx(xK,{...t,children:h.jsx(IK,{...n,children:h.jsx(YK,{ref:i,className:ge("bg-panel border border-border rounded-md py-1 shadow-lg z-50",e),...s})})}));eZ.displayName="SelectContent";const tZ=_.forwardRef(({className:e,...t},n)=>h.jsx(WK,{ref:n,className:ge("font-mono text-[11px] px-3 py-1.5 text-neutral-400 cursor-pointer hover:bg-white/[0.03] hover:text-white data-[highlighted]:bg-white/[0.03] data-[highlighted]:text-white outline-none",e),...t}));tZ.displayName="SelectItem";const nZ=_.forwardRef(({className:e,...t},n)=>h.jsx("textarea",{ref:n,className:ge("bg-surface border border-border rounded-md px-3 py-2 font-mono text-[12px] text-foreground outline-none w-full transition focus:border-flow placeholder:text-neutral-600 resize-none min-h-[80px]",e),...t}));nZ.displayName="Textarea";const JA=_.createContext(void 0);function rZ(e=!0){const t=_.useContext(JA);if(t===void 0&&!e)throw new Error(yn(7));return t}function ek(e={}){const{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:s}=jj(),{ref:i,index:a}=dx(e),l=n===a,f=_.useRef(null),d=so(i,f);return{compositeProps:_.useMemo(()=>({tabIndex:l?0:-1,onFocus(){s(a)},onMouseMove(){const g=f.current;if(!t||!g)return;const y=g.hasAttribute("disabled")||g.ariaDisabled==="true";!l&&!y&&g.focus()}}),[l,s,a,t]),compositeRef:d,index:a}}function sZ(e){const{render:t,className:n,state:s=an,props:i=Eu,refs:a=Eu,metadata:l,stateAttributesMapping:f,tag:d="div",...p}=e,{compositeProps:g,compositeRef:y}=ek({metadata:l});return zt(d,e,{state:s,ref:[...a,y],props:[g,...i,p],stateAttributesMapping:f})}const oZ=_.forwardRef(function(t,n){const{className:s,defaultPressed:i=!1,disabled:a=!1,form:l,onPressedChange:f,pressed:d,render:p,type:g,value:y,nativeButton:b=!0,...x}=t,S=br(y||void 0),w=rZ(),T=w?.value??[],C=w?void 0:i,O=(a||w?.disabled)??!1,[N,R]=pp({controlled:w?S!==void 0&&T.indexOf(S)>-1:d,default:C,name:"Toggle",state:"pressed"}),M=ke((U,Z)=>{S&&w?.setGroupValue?.(S,U,Z),f?.(U,Z)}),{getButtonProps:z,buttonRef:j}=Jc({disabled:O,native:b}),A={disabled:O,pressed:N},P=[j,n],Q=[{"aria-pressed":N,onClick(U){const Z=!N,G=Yt(ii,U.nativeEvent);M(Z,G),!G.isCanceled&&R(Z)}},x,z],B=zt("button",t,{enabled:!w,state:A,ref:P,props:Q});return w?h.jsx(sZ,{tag:"button",render:p,className:s,state:A,refs:P,props:Q}):B}),Dr=_.forwardRef(({className:e,...t},n)=>h.jsx(oZ,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 border border-transparent rounded-sm px-2.5 py-1 cursor-pointer transition-all hover:text-neutral-300 data-[pressed]:text-white data-[pressed]:border-border-bright data-[pressed]:bg-white/[0.03]",e),...t}));Dr.displayName="Toggle";function iZ(e){return e==null||e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}const tk="data-composite-item-active",aZ=[];function cZ(e){const{itemSizes:t,cols:n=1,loopFocus:s=!0,dense:i=!1,orientation:a="both",direction:l,highlightedIndex:f,onHighlightedIndexChange:d,rootRef:p,enableHomeAndEndKeys:g=!1,stopEventPropagation:y=!1,disabledIndices:b,modifierKeys:x=aZ}=e,[S,w]=_.useState(0),T=n>1,C=_.useRef(null),O=so(C,p),N=_.useRef([]),R=_.useRef(!1),M=f??S,z=ke((P,Q=!1)=>{if((d??w)(P),Q){const B=N.current[P];zC(C.current,B,l,a)}}),j=ke(P=>{if(P.size===0||R.current)return;R.current=!0;const Q=Array.from(P.keys()),B=Q.find(Z=>Z?.hasAttribute(tk))??null,U=B?Q.indexOf(B):-1;U!==-1&&z(U),zC(C.current,B,l,a)}),A=_.useMemo(()=>({"aria-orientation":a==="both"?void 0:a,ref:O,onFocus(P){!C.current||!DC(P.target)||P.target.setSelectionRange(0,P.target.value.length??0)},onKeyDown(P){const Q=g?LK:XA;if(!Q.has(P.key)||lZ(P,x)||!C.current)return;const U=l==="rtl",Z=U?Ru:Ec,G={horizontal:Z,vertical:Wi,both:Z}[a],ee=U?Ec:Ru,D={horizontal:ee,vertical:wc,both:ee}[a];if(DC(P.target)&&!iZ(P.target)){const W=P.target.selectionStart,Y=P.target.selectionEnd,ae=P.target.value??"";if(W==null||P.shiftKey||W!==Y||P.key!==D&&W<ae.length||P.key!==G&&W>0)return}let K=M;const q=wV(N,b),V=EV(N,b);if(T){const W=t||Array.from({length:N.current.length},()=>({width:1,height:1})),Y=CV(W,n,i),ae=Y.findIndex(fe=>fe!=null&&!fu(N,fe,b)),se=Y.reduce((fe,Se,pe)=>Se!=null&&!fu(N,Se,b)?pe:fe,-1);K=Y[TV({current:Y.map(fe=>fe?N.current[fe]:null)},{event:P,orientation:a,loopFocus:s,cols:n,disabledIndices:NV([...b||N.current.map((fe,Se)=>fu(N,Se)?Se:void 0),void 0],Y),minIndex:ae,maxIndex:se,prevIndex:RV(M>V?q:M,W,Y,n,P.key===Wi?"bl":P.key===Ec?"tr":"tl"),rtl:U})]}const L={horizontal:[Z],vertical:[Wi],both:[Z,Wi]}[a],I={horizontal:[ee],vertical:[wc],both:[ee,wc]}[a],H=T?Q:{horizontal:g?DK:ZA,vertical:g?zK:YA,both:Q}[a];g&&(P.key===Ju?K=q:P.key===ef&&(K=V)),K===M&&(L.includes(P.key)||I.includes(P.key))&&(s&&K===V&&L.includes(P.key)?K=q:s&&K===q&&I.includes(P.key)?K=V:K=fr(N,{startingIndex:K,decrement:I.includes(P.key),disabledIndices:b})),K!==M&&!ch(N,K)&&(y&&P.stopPropagation(),H.has(P.key)&&P.preventDefault(),z(K,!0),queueMicrotask(()=>{N.current[K]?.focus()}))}}),[n,i,l,b,N,g,M,T,t,s,O,x,z,a,y]);return _.useMemo(()=>({props:A,highlightedIndex:M,onHighlightedIndexChange:z,elementsRef:N,disabledIndices:b,onMapChange:j,relayKeyboardEvent:A.onKeyDown}),[A,M,z,N,b,j])}function lZ(e,t){for(const n of HK.values())if(!t.includes(n)&&e.getModifierState(n))return!0;return!1}function nk(e){const{render:t,className:n,refs:s=Eu,props:i=Eu,state:a=an,stateAttributesMapping:l,highlightedIndex:f,onHighlightedIndexChange:d,orientation:p,dense:g,itemSizes:y,loopFocus:b,cols:x,enableHomeAndEndKeys:S,onMapChange:w,stopEventPropagation:T=!0,rootRef:C,disabledIndices:O,modifierKeys:N,highlightItemOnHover:R=!1,tag:M="div",...z}=e,j=IA(),{props:A,highlightedIndex:P,onHighlightedIndexChange:Q,elementsRef:B,onMapChange:U,relayKeyboardEvent:Z}=cZ({itemSizes:y,cols:x,loopFocus:b,dense:g,orientation:p,highlightedIndex:f,onHighlightedIndexChange:d,rootRef:C,stopEventPropagation:T,enableHomeAndEndKeys:S,direction:j,disabledIndices:O,modifierKeys:N}),G=zt(M,e,{state:a,ref:s,props:[A,...i,z],stateAttributesMapping:l}),ee=_.useMemo(()=>({highlightedIndex:P,onHighlightedIndexChange:Q,highlightItemOnHover:R,relayKeyboardEvent:Z}),[P,Q,R,Z]);return h.jsx(Nj.Provider,{value:ee,children:h.jsx(HA,{elementsRef:B,onMapChange:D=>{w?.(D),U(D)},children:G})})}let uZ=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e.multiple="data-multiple",e})({});const FC={multiple(e){return e?{[uZ.multiple]:""}:null}},fZ=_.forwardRef(function(t,n){const{defaultValue:s,disabled:i=!1,loopFocus:a=!0,onValueChange:l,orientation:f="horizontal",multiple:d=!1,value:p,className:g,render:y,...b}=t,x=KA(),S=_.useMemo(()=>{if(p===void 0)return s??[]},[p,s]),w=_.useMemo(()=>p!==void 0||s!==void 0,[p,s]),T=(x?.disabled??!1)||i,[C,O]=pp({controlled:p,default:S,name:"ToggleGroup",state:"value"}),N=ke((A,P,Q)=>{let B;if(d?(B=C.slice(),P?B.push(A):B.splice(C.indexOf(A),1)):B=P?[A]:[],Array.isArray(B)){if(l?.(B,Q),Q.isCanceled)return;O(B)}}),R={disabled:T,multiple:d,orientation:f},M=_.useMemo(()=>({disabled:T,orientation:f,setGroupValue:N,value:C,isValueInitialized:w}),[T,f,N,C,w]),z={role:"group"},j=zt("div",t,{enabled:!!x,state:R,ref:n,props:[z,b],stateAttributesMapping:FC});return h.jsx(JA.Provider,{value:M,children:x?j:h.jsx(nk,{render:y,className:g,state:R,refs:[n],props:[z,b],stateAttributesMapping:FC,loopFocus:a,enableHomeAndEndKeys:!0})})}),dh=_.forwardRef(({className:e,...t},n)=>h.jsx(fZ,{ref:n,className:ge("flex items-center gap-0.5",e),...t}));dh.displayName="ToggleGroup";const dZ=ge($j({variant:"secondary",size:"sm"}),"h-7 whitespace-nowrap uppercase tracking-[0.08em] leading-none no-underline");function rk({active:e,onClick:t,children:n,className:s}){return h.jsxs("button",{type:"button",onClick:t,className:ge("font-mono text-[10px] tracking-[1.5px] uppercase bg-transparent border-none px-3.5 py-1 cursor-pointer relative transition-colors",e?"text-white":"text-neutral-500 hover:text-neutral-300",s),children:[n,e&&h.jsx("span",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 w-4 h-0.5 bg-flow rounded-sm shadow-[0_0_8px_rgba(59,130,246,0.5)]"})]})}function hZ({items:e,activeId:t,onItemChange:n,renderItem:s,className:i}){return h.jsx("div",{className:ge("flex items-center gap-0.5",i),children:e.map(a=>{const l=a.id===t,f=()=>n?.(a.id);return s?h.jsx("span",{children:s(a,{active:l,onClick:f})},a.id):h.jsx(rk,{active:l,onClick:f,children:a.label},a.id)})})}const pZ=gi("rounded-full inline-block flex-shrink-0",{variants:{color:{healthy:"bg-healthy",syncing:"bg-syncing",offline:"bg-offline",flow:"bg-flow",relay:"bg-relay",encrypt:"bg-encrypt",muted:"bg-neutral-500"},size:{sm:"w-1.5 h-1.5",md:"w-2 h-2",lg:"w-2.5 h-2.5"},glow:{true:"",false:""}},defaultVariants:{color:"healthy",size:"sm",glow:!1}}),mZ={healthy:"0 0 6px #22c55e",syncing:"0 0 6px #f59e0b",offline:"0 0 6px #ef4444",flow:"0 0 6px #3b82f6",relay:"0 0 6px #8b5cf6",encrypt:"0 0 6px #f472b6",muted:"none"};function gZ({color:e,size:t,glow:n,pulse:s,className:i}){return h.jsx("span",{className:ge(pZ({color:e,size:t,glow:n}),s&&"dot-pulse",i),style:n?{boxShadow:mZ[e??"healthy"]}:void 0})}const yZ="0.0.6-56",vZ={version:yZ},bZ=vZ.version;function xZ({label:e,className:t}){return h.jsxs("div",{className:ge("flex items-center gap-3",t),children:[h.jsx(gZ,{color:"healthy",size:"md",glow:!0}),h.jsx("span",{className:"font-display font-bold text-white text-sm tracking-tight",children:"syncular"}),e&&h.jsx("span",{className:"font-mono text-[9px] text-neutral-600 uppercase tracking-widest",children:e}),h.jsxs("span",{className:"font-mono text-[9px] text-neutral-600 tracking-wider",children:["v",bZ]})]})}function SZ({brand:e,center:t,right:n,className:s}){return h.jsxs(h.Fragment,{children:[h.jsx("div",{"aria-hidden":"true",className:"h-[42px] shrink-0"}),h.jsxs("nav",{className:ge("fixed top-0 left-0 right-0 z-100 h-[42px] border-b border-border bg-surface/88 backdrop-blur-lg flex items-center justify-between px-5",s),children:[h.jsx("div",{className:"flex items-center gap-3",children:e}),h.jsx("div",{className:"flex items-center gap-0.5",children:t}),h.jsx("div",{className:"flex items-center gap-2",children:n})]})]})}const _Z=gi("border rounded-lg p-3 font-mono text-[11px]",{variants:{variant:{default:"border-border bg-panel",destructive:"border-offline/20 bg-offline/5 text-offline"}},defaultVariants:{variant:"default"}}),In=_.forwardRef(({className:e,variant:t,...n},s)=>h.jsx("div",{ref:s,role:"alert",className:ge(_Z({variant:t,className:e})),...n}));In.displayName="Alert";const tf=_.forwardRef(({className:e,...t},n)=>h.jsx("h5",{ref:n,className:ge("font-medium text-white mb-1",e),...t}));tf.displayName="AlertTitle";const Pn=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("text-neutral-400",e),...t}));Pn.displayName="AlertDescription";const sk=_.createContext(void 0);function rl(e){const t=_.useContext(sk);if(e===!1&&t===void 0)throw new Error(yn(27));return t}const wZ={...nl,...ba},hx=_.forwardRef(function(t,n){const{render:s,className:i,forceRender:a=!1,...l}=t,{store:f}=rl(),d=f.useState("open"),p=f.useState("nested"),g=f.useState("mounted"),y=f.useState("transitionStatus");return zt("div",t,{state:{open:d,transitionStatus:y},ref:[f.context.backdropRef,n],stateAttributesMapping:wZ,props:[{role:"presentation",hidden:!g,style:{userSelect:"none",WebkitUserSelect:"none"}},l],enabled:a||!p})}),ok=_.forwardRef(function(t,n){const{render:s,className:i,id:a,...l}=t,{store:f}=rl(),d=br(a);return f.useSyncedValueWithCleanup("descriptionElementId",d),zt("p",t,{ref:n,props:[{id:d},l]})});let EZ=(function(e){return e.nestedDialogs="--nested-dialogs",e})({}),TZ=(function(e){return e[e.open=Qi.open]="open",e[e.closed=Qi.closed]="closed",e[e.startingStyle=Qi.startingStyle]="startingStyle",e[e.endingStyle=Qi.endingStyle]="endingStyle",e.nested="data-nested",e.nestedDialogOpen="data-nested-dialog-open",e})({});const ik=_.createContext(void 0);function CZ(){const e=_.useContext(ik);if(e===void 0)throw new Error(yn(26));return e}const RZ={...nl,...ba,nestedDialogOpen(e){return e?{[TZ.nestedDialogOpen]:""}:null}},ak=_.forwardRef(function(t,n){const{className:s,finalFocus:i,initialFocus:a,render:l,...f}=t,{store:d}=rl(),p=d.useState("descriptionElementId"),g=d.useState("disablePointerDismissal"),y=d.useState("floatingRootContext"),b=d.useState("popupProps"),x=d.useState("modal"),S=d.useState("mounted"),w=d.useState("nested"),T=d.useState("nestedOpenDialogCount"),C=d.useState("open"),O=d.useState("openMethod"),N=d.useState("titleElementId"),R=d.useState("transitionStatus"),M=d.useState("role");CZ(),xa({open:C,ref:d.context.popupRef,onComplete(){C&&d.context.onOpenChangeComplete?.(!0)}});function z(B){return B==="touch"?d.context.popupRef.current:!0}const j=a===void 0?z:a,A=T>0,Q=zt("div",t,{state:{open:C,nested:w,transitionStatus:R,nestedDialogOpen:A},props:[b,{"aria-labelledby":N??void 0,"aria-describedby":p??void 0,role:M,tabIndex:-1,hidden:!S,onKeyDown(B){QA.has(B.key)&&B.stopPropagation()},style:{[EZ.nestedDialogs]:T}},f],ref:[n,d.context.popupRef,d.useStateSetter("popupElement")],stateAttributesMapping:RZ});return h.jsx(_A,{context:y,openInteractionType:O,disabled:!S,closeOnFocusOut:!g,initialFocus:j,returnFocus:i,modal:x!==!1,restoreFocus:"popup",children:Q})}),ck=_.forwardRef(function(t,n){const{keepMounted:s=!1,...i}=t,{store:a}=rl(),l=a.useState("mounted"),f=a.useState("modal"),d=a.useState("open");return l||s?h.jsx(ik.Provider,{value:s,children:h.jsxs(SA,{ref:n,...i,children:[l&&f===!0&&h.jsx(VA,{ref:a.context.internalBackdropRef,inert:fx(!d)}),t.children]})}):null});function NZ(e){const{store:t,parentContext:n,actionsRef:s}=e,i=t.useState("open"),a=t.useState("disablePointerDismissal"),l=t.useState("modal"),f=t.useState("popupElement"),{openMethod:d,triggerProps:p,reset:g}=pK(i);sG(t);const{forceUnmount:y}=oG(i,t,()=>{g()}),b=ke(Q=>{const B=Yt(Q);return B.preventUnmountOnClose=()=>{t.set("preventUnmountingOnClose",!0)},B}),x=_.useCallback(()=>{t.setOpen(!1,b(b8))},[t,b]);_.useImperativeHandle(s,()=>({unmount:y,close:x}),[y,x]);const S=fG({popupStore:t,onOpenChange:t.setOpen,treatPopupAsFloatingElement:!0,noEmit:!0}),[w,T]=_.useState(0),C=w===0,O=xG(S),N=G7(S,{outsidePressEvent(){return t.context.internalBackdropRef.current||t.context.backdropRef.current?"intentional":{mouse:l==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}},outsidePress(Q){if(!t.context.outsidePressEnabledRef.current||"button"in Q&&Q.button!==0||"touches"in Q&&Q.touches.length!==1)return!1;const B=Ur(Q);if(C&&!a){const U=B;return l&&(t.context.internalBackdropRef.current||t.context.backdropRef.current)?t.context.internalBackdropRef.current===U||t.context.backdropRef.current===U||Ot(U,f)&&!U?.hasAttribute("data-base-ui-portal"):!0}return!1},escapeKey:C});BA(i&&l===!0,f);const{getReferenceProps:R,getFloatingProps:M,getTriggerProps:z}=vG([O,N]);t.useContextCallback("onNestedDialogOpen",Q=>{T(Q+1)}),t.useContextCallback("onNestedDialogClose",()=>{T(0)}),_.useEffect(()=>(n?.onNestedDialogOpen&&i&&n.onNestedDialogOpen(w),n?.onNestedDialogClose&&!i&&n.onNestedDialogClose(),()=>{n?.onNestedDialogClose&&i&&n.onNestedDialogClose()}),[i,n,w]);const j=_.useMemo(()=>R(p),[R,p]),A=_.useMemo(()=>z(p),[z,p]),P=_.useMemo(()=>M(),[M]);t.useSyncedValues({openMethod:d,activeTriggerProps:j,inactiveTriggerProps:A,popupProps:P,floatingRootContext:S,nestedOpenDialogCount:w})}const jZ={...cG,modal:Pe(e=>e.modal),nested:Pe(e=>e.nested),nestedOpenDialogCount:Pe(e=>e.nestedOpenDialogCount),disablePointerDismissal:Pe(e=>e.disablePointerDismissal),openMethod:Pe(e=>e.openMethod),descriptionElementId:Pe(e=>e.descriptionElementId),titleElementId:Pe(e=>e.titleElementId),viewportElement:Pe(e=>e.viewportElement),role:Pe(e=>e.role)};class AZ extends kA{constructor(t){super(kZ(t),{popupRef:_.createRef(),backdropRef:_.createRef(),internalBackdropRef:_.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:new lx,onOpenChange:void 0,onOpenChangeComplete:void 0},jZ)}setOpen=(t,n)=>{if(n.preventUnmountOnClose=()=>{this.set("preventUnmountingOnClose",!0)},!t&&n.trigger==null&&this.state.activeTriggerId!=null&&(n.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(t,n),n.isCanceled)return;const s={open:t,nativeEvent:n.event,reason:n.reason,nested:this.state.nested};this.state.floatingRootContext.context.events?.emit("openchange",s);const i={open:t},a=n.trigger?.id??null;(a||t)&&(i.activeTriggerId=a,i.activeTriggerElement=n.trigger??null),this.update(i)}}function kZ(e={}){return{...aG(),modal:!0,disablePointerDismissal:!1,popupElement:null,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,role:"dialog",...e}}function OZ(e){const{children:t,open:n,defaultOpen:s=!1,onOpenChange:i,onOpenChangeComplete:a,disablePointerDismissal:l=!1,modal:f=!0,actionsRef:d,handle:p,triggerId:g,defaultTriggerId:y=null}=e,b=rl(!0),x=!!b,S=zn(()=>p?.store??new AZ({open:s,openProp:n,activeTriggerId:y,triggerIdProp:g,modal:f,disablePointerDismissal:l,nested:x})).current;Z8(()=>{n===void 0&&S.state.open===!1&&s===!0&&S.update({open:!0,activeTriggerId:y})}),S.useControlledProp("openProp",n),S.useControlledProp("triggerIdProp",g),S.useSyncedValues({disablePointerDismissal:l,nested:x,modal:f}),S.useContextCallback("onOpenChange",i),S.useContextCallback("onOpenChangeComplete",a);const w=S.useState("payload");NZ({store:S,actionsRef:d,parentContext:b?.store.context});const T=_.useMemo(()=>({store:S}),[S]);return h.jsx(sk.Provider,{value:T,children:typeof t=="function"?t({payload:w}):t})}const lk=_.forwardRef(function(t,n){const{render:s,className:i,id:a,...l}=t,{store:f}=rl(),d=br(a);return f.useSyncedValueWithCleanup("titleElementId",d),zt("h2",t,{ref:n,props:[{id:d},l]})}),$r=OZ,MZ=_.forwardRef(({className:e,...t},n)=>h.jsx(hx,{ref:n,className:ge("fixed inset-0 z-50 bg-black/60 backdrop-blur-sm",e),...t}));MZ.displayName="DialogOverlay";const hr=_.forwardRef(({className:e,children:t,...n},s)=>h.jsxs(ck,{children:[h.jsx(hx,{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm"}),h.jsx(ak,{ref:s,className:ge("fixed z-50 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-panel border border-border rounded-lg shadow-lg max-w-lg w-full p-0",e),...n,children:t})]}));hr.displayName="DialogContent";const pr=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-b border-border",e),...t}));pr.displayName="DialogHeader";const Nn=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-t border-border flex justify-end gap-2",e),...t}));Nn.displayName="DialogFooter";const mr=_.forwardRef(({className:e,...t},n)=>h.jsx(lk,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 uppercase tracking-widest",e),...t}));mr.displayName="DialogTitle";const IZ=_.forwardRef(({className:e,...t},n)=>h.jsx(ok,{ref:n,className:ge("font-mono text-[10px] text-neutral-500",e),...t}));IZ.displayName="DialogDescription";const px=_.forwardRef(({className:e,page:t,totalPages:n,totalItems:s,onPageChange:i,...a},l)=>h.jsxs("div",{ref:l,className:ge("px-5 py-2.5 border-t border-border flex items-center justify-between",e),...a,children:[h.jsxs("span",{className:"font-mono text-[10px] text-neutral-600",children:[s," items · Page ",t," of ",n]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(Ne,{size:"sm",variant:"default",disabled:t<=1,onClick:()=>i(t-1),children:"Prev"}),h.jsx(Ne,{size:"sm",variant:"default",disabled:t>=n,onClick:()=>i(t+1),children:"Next"})]})]}));px.displayName="Pagination";const PZ=_.forwardRef(({className:e,orientation:t="horizontal",...n},s)=>h.jsx("hr",{ref:s,"aria-orientation":t==="vertical"?"vertical":void 0,className:ge("border-none m-0",t==="horizontal"?"h-px w-full bg-border":"w-px h-4 bg-border",e),...n}));PZ.displayName="Separator";const DZ=gi("fixed z-50 bg-panel shadow-lg overflow-auto",{variants:{side:{top:"top-0 left-0 w-full h-[400px] border-b border-border",right:"right-0 top-0 h-full w-[400px] border-l border-border",bottom:"bottom-0 left-0 w-full h-[400px] border-t border-border",left:"left-0 top-0 h-full w-[400px] border-r border-border"}},defaultVariants:{side:"right"}}),zZ=_.forwardRef(({className:e,side:t,children:n,...s},i)=>h.jsxs(ck,{children:[h.jsx(hx,{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm"}),h.jsx(ak,{ref:i,className:ge(DZ({side:t,className:e})),...s,children:n})]}));zZ.displayName="SheetContent";const LZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-b border-border",e),...t}));LZ.displayName="SheetHeader";const UZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("px-5 py-3 border-t border-border flex justify-end gap-2",e),...t}));UZ.displayName="SheetFooter";const $Z=_.forwardRef(({className:e,...t},n)=>h.jsx(lk,{ref:n,className:ge("font-mono text-[10px] text-neutral-500 uppercase tracking-widest",e),...t}));$Z.displayName="SheetTitle";const BZ=_.forwardRef(({className:e,...t},n)=>h.jsx(ok,{ref:n,className:ge("text-sm text-neutral-400",e),...t}));BZ.displayName="SheetDescription";const FZ=_.forwardRef(({className:e,...t},n)=>h.jsx("div",{ref:n,className:ge("rounded-md bg-neutral-800 animate-pulse",e),...t}));FZ.displayName="Skeleton";const HZ=_.createContext(void 0);function mx(){const e=_.useContext(HZ);if(e===void 0)throw new Error(yn(64));return e}let qZ=(function(e){return e.activationDirection="data-activation-direction",e.orientation="data-orientation",e})({});const uk={tabActivationDirection:e=>({[qZ.activationDirection]:e})},fk=_.createContext(void 0);function VZ(){const e=_.useContext(fk);if(e===void 0)throw new Error(yn(65));return e}const GZ=_.forwardRef(function(t,n){const{className:s,disabled:i=!1,render:a,value:l,id:f,nativeButton:d=!0,...p}=t,{value:g,getTabPanelIdByValue:y,orientation:b}=mx(),{activateOnFocus:x,highlightedTabIndex:S,onTabActivation:w,setHighlightedTabIndex:T,tabsListElement:C}=VZ(),O=br(f),N=_.useMemo(()=>({disabled:i,id:O,value:l}),[i,O,l]),{compositeProps:R,compositeRef:M,index:z}=ek({metadata:N}),j=l===g,A=_.useRef(!1);Le(()=>{if(A.current){A.current=!1;return}if(!(j&&z>-1&&S!==z))return;const V=C;if(V!=null){const L=Fo(Rt(V));if(L&&Ot(V,L))return}i||T(z)},[j,z,S,T,i,C]);const{getButtonProps:P,buttonRef:Q}=Jc({disabled:i,native:d,focusableWhenDisabled:!0}),B=y(l),U=_.useRef(!1),Z=_.useRef(!1);function G(V){j||i||w(l,Yt(ii,V.nativeEvent,void 0,{activationDirection:"none"}))}function ee(V){j||(z>-1&&!i&&T(z),!i&&x&&(!U.current||U.current&&Z.current)&&w(l,Yt(ii,V.nativeEvent,void 0,{activationDirection:"none"})))}function D(V){if(j||i)return;U.current=!0;function L(){U.current=!1,Z.current=!1}(!V.button||V.button===0)&&(Z.current=!0,Rt(V.currentTarget).addEventListener("pointerup",L,{once:!0}))}return zt("button",t,{state:{disabled:i,active:j,orientation:b},ref:[n,Q,M],props:[R,{role:"tab","aria-controls":B,"aria-selected":j,id:O,onClick:G,onFocus:ee,onPointerDown:D,[tk]:j?"":void 0,onKeyDownCapture(){A.current=!0}},p,P]})});let KZ=(function(e){return e.index="data-index",e.activationDirection="data-activation-direction",e.orientation="data-orientation",e.hidden="data-hidden",e})({});const ZZ={...uk,...ba},YZ=_.forwardRef(function(t,n){const{className:s,value:i,render:a,keepMounted:l=!1,...f}=t,{value:d,getTabIdByPanelValue:p,orientation:g,tabActivationDirection:y,registerMountedTabPanel:b,unregisterMountedTabPanel:x}=mx(),S=br(),w=_.useMemo(()=>({id:S,value:i}),[S,i]),{ref:T,index:C}=dx({metadata:w}),O=i===d,{mounted:N,transitionStatus:R,setMounted:M}=Rp(O),z=!N,j=p(i),A={hidden:z,orientation:g,tabActivationDirection:y,transitionStatus:R},P=_.useRef(null),Q=zt("div",t,{state:A,ref:[n,T,P],props:[{"aria-labelledby":j,hidden:z,id:S,role:"tabpanel",tabIndex:O?0:-1,inert:fx(!O),[KZ.index]:C},f],stateAttributesMapping:ZZ});return xa({open:O,ref:P,onComplete(){O||M(!1)}}),Le(()=>{if(!(z&&!l)&&S!=null)return b(i,S),()=>{x(i,S)}},[z,l,i,S,b,x]),l||N?Q:null}),XZ=_.forwardRef(function(t,n){const{activateOnFocus:s=!1,className:i,loopFocus:a=!0,render:l,...f}=t,{getTabElementBySelectedValue:d,onValueChange:p,orientation:g,value:y,setTabMap:b,tabActivationDirection:x}=mx(),[S,w]=_.useState(0),[T,C]=_.useState(null),O=QZ(y,g,T,d),N=ke((j,A)=>{if(j!==y){const P=O(j);A.activationDirection=P,p(j,A)}}),R={orientation:g,tabActivationDirection:x},M={"aria-orientation":g==="vertical"?"vertical":void 0,role:"tablist"},z=_.useMemo(()=>({activateOnFocus:s,highlightedTabIndex:S,onTabActivation:N,setHighlightedTabIndex:w,tabsListElement:T,value:y}),[s,S,N,w,T,y]);return h.jsx(fk.Provider,{value:z,children:h.jsx(nk,{render:l,className:i,state:R,refs:[n,C],props:[M,f],stateAttributesMapping:uk,highlightedIndex:S,enableHomeAndEndKeys:!0,loopFocus:a,orientation:g,onHighlightedIndexChange:w,onMapChange:b,disabledIndices:Eu})})});function HC(e,t){const{left:n,top:s}=e.getBoundingClientRect(),{left:i,top:a}=t.getBoundingClientRect(),l=n-i,f=s-a;return{left:l,top:f}}function QZ(e,t,n,s){const[i,a]=_.useState(null);return Le(()=>{if(e==null||n==null){a(null);return}const l=s(e);if(l==null){a(null);return}const{left:f,top:d}=HC(l,n);a(t==="horizontal"?f:d)},[t,s,n,e]),_.useCallback(l=>{if(l===e)return"none";if(l==null)return a(null),"none";if(l!=null&&n!=null){const f=s(l);if(f!=null){const{left:d,top:p}=HC(f,n);if(i==null)return a(t==="horizontal"?d:p),"none";if(t==="horizontal"){if(d<i)return a(d),"left";if(d>i)return a(d),"right"}else{if(p<i)return a(p),"up";if(p>i)return a(p),"down"}}}return"none"},[s,t,i,n,e])}const WZ=_.forwardRef(({className:e,...t},n)=>h.jsx(XZ,{ref:n,className:ge("flex items-center gap-0.5",e),...t}));WZ.displayName="TabsList";const JZ=gi("inline-flex items-center justify-center cursor-pointer transition-all outline-none",{variants:{variant:{default:"font-mono text-[10px] text-neutral-500 border border-transparent rounded-sm px-2.5 py-1 hover:text-neutral-300 data-[selected]:text-white data-[selected]:border-border-bright data-[selected]:bg-white/[0.03]",pills:"font-mono text-[10px] text-neutral-500 border border-transparent rounded-full px-3 py-1 hover:text-neutral-300 data-[selected]:text-white data-[selected]:border-border-bright data-[selected]:bg-white/[0.03]"}},defaultVariants:{variant:"default"}}),eY=_.forwardRef(({className:e,variant:t,...n},s)=>h.jsx(GZ,{ref:s,className:ge(JZ({variant:t,className:e})),...n}));eY.displayName="TabsTrigger";const tY=_.forwardRef(({className:e,...t},n)=>h.jsx(YZ,{ref:n,className:ge("outline-none",e),...t}));tY.displayName="TabsContent";const nY=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("font-mono text-[11px] text-neutral-300",e),...t}));nY.displayName="Text";const rY=_.forwardRef(({className:e,...t},n)=>h.jsx("p",{ref:n,className:ge("font-mono text-[10px] text-neutral-500",e),...t}));rY.displayName="TextMuted";const sY=_.forwardRef(({className:e,...t},n)=>h.jsx("code",{ref:n,className:ge("font-mono text-[11px] text-white",e),...t}));sY.displayName="TextCode";const oY=_.forwardRef(({className:e,...t},n)=>h.jsx("span",{ref:n,className:ge("font-mono text-[9px] uppercase tracking-wider text-neutral-500",e),...t}));oY.displayName="TextLabel";const iY=_.forwardRef(({className:e,...t},n)=>h.jsx("pre",{ref:n,className:ge("font-mono text-[11px] text-neutral-300 p-3 rounded border border-border bg-panel-alt overflow-x-auto",e),...t}));iY.displayName="CodeBlock";const dk=(...e)=>e.filter((t,n,s)=>!!t&&t.trim()!==""&&s.indexOf(t)===n).join(" ").trim();const aY=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();const cY=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,s)=>s?s.toUpperCase():n.toLowerCase());const qC=e=>{const t=cY(e);return t.charAt(0).toUpperCase()+t.slice(1)};var lY={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const uY=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};const fY=_.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:s,className:i="",children:a,iconNode:l,...f},d)=>_.createElement("svg",{ref:d,...lY,width:t,height:t,stroke:e,strokeWidth:s?Number(n)*24/Number(t):n,className:dk("lucide",i),...!a&&!uY(f)&&{"aria-hidden":"true"},...f},[...l.map(([p,g])=>_.createElement(p,g)),...Array.isArray(a)?a:[a]]));const hk=(e,t)=>{const n=_.forwardRef(({className:s,...i},a)=>_.createElement(fY,{ref:a,iconNode:t,className:dk(`lucide-${aY(qC(e))}`,`lucide-${e}`,s),...i}));return n.displayName=qC(e),n};const dY=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],hY=hk("arrow-left",dY);const pY=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],mY=hk("settings",pY),gY="console:instance-id";function Lt(){const[e,t]=pi(gY,""),n=e.trim();return _.useMemo(()=>({instanceId:n.length>0?n:void 0,rawInstanceId:e,setInstanceId:t,clearInstanceId:()=>t("")}),[n,e,t])}const Jn={stats:e=>["console","stats",e],timeseries:e=>["console","stats","timeseries",e],latency:e=>["console","stats","latency",e],commits:e=>["console","commits",e],commitDetail:(e,t,n)=>["console","commit-detail",e,t,n],timeline:e=>["console","timeline",e],clients:e=>["console","clients",e],eventDetail:(e,t,n)=>["console","event-detail",e,t,n],eventPayload:(e,t,n)=>["console","event-payload",e,t,n],handlers:e=>["console","handlers",e],prunePreview:e=>["console","prune","preview",e],operations:e=>["console","operations",e],apiKeys:e=>["console","api-keys",e],storage:e=>["console","storage",e]};function _i(e,t){return e===0?!1:e??t}function nf(e,t){return t?{...e,instanceId:t}:e}function Sa(e){return encodeURIComponent(String(e))}function Ln(e,t,n){const s=e.endsWith("/")?e.slice(0,-1):e,i=n?.toString();return`${s}${t}${i?`?${i}`:""}`}function rf(e={}){const t=Vt(),{instanceId:n}=Lt(),s=e.instanceId??n,i=nf(e.partitionId?{partitionId:e.partitionId}:{},s);return Wn({queryKey:Jn.stats({partitionId:e.partitionId,instanceId:s}),queryFn:()=>{if(!t)throw new Error("Not connected");return Gu(t.GET("/console/stats",{params:{query:i}}))},enabled:!!t,refetchInterval:_i(e.refetchIntervalMs,5e3)})}function yY(e={},t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=e.instanceId??i;return Wn({queryKey:Jn.timeseries({...e,instanceId:a}),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");const l=new URLSearchParams;e.interval&&l.set("interval",e.interval),e.range&&l.set("range",e.range),e.partitionId&&l.set("partitionId",e.partitionId),a&&l.set("instanceId",a);const f=await fetch(`${s.serverUrl}/console/stats/timeseries?${l}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!f.ok)throw new Error("Failed to fetch timeseries stats");return f.json()},enabled:(t.enabled??!0)&&!!n&&!!s,refetchInterval:_i(t.refetchIntervalMs,3e4)})}function vY(e={},t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=e.instanceId??i;return Wn({queryKey:Jn.latency({...e,instanceId:a}),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");const l=new URLSearchParams;e.range&&l.set("range",e.range),e.partitionId&&l.set("partitionId",e.partitionId),a&&l.set("instanceId",a);const f=await fetch(`${s.serverUrl}/console/stats/latency?${l}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!f.ok)throw new Error("Failed to fetch latency stats");return f.json()},enabled:(t.enabled??!0)&&!!n&&!!s,refetchInterval:_i(t.refetchIntervalMs,3e4)})}function bY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId},i);return Wn({queryKey:Jn.commits({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/commits",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function xY(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.commitDetail(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Commit sequence is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/commits/${Sa(e)}${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch commit detail");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function SY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId,view:e.view,eventType:e.eventType,actorId:e.actorId,clientId:e.clientId,requestId:e.requestId,traceId:e.traceId,table:e.table,outcome:e.outcome,search:e.search,from:e.from,to:e.to},i);return Wn({queryKey:Jn.timeline({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/timeline",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function pk(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,partitionId:e.partitionId},i);return Wn({queryKey:Jn.clients({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/clients",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function _Y(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.eventDetail(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Event id is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/events/${Sa(e)}${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch event detail");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function wY(e,t={}){const n=Vt(),{config:s}=Dt(),{instanceId:i}=Lt(),a=t.instanceId??i;return Wn({queryKey:Jn.eventPayload(e,t.partitionId,a),queryFn:async()=>{if(!n||!s)throw new Error("Not connected");if(e===void 0)throw new Error("Event id is required");const l=new URLSearchParams;t.partitionId&&l.set("partitionId",t.partitionId),a&&l.set("instanceId",a);const f=l.toString(),d=await fetch(`${s.serverUrl}/console/events/${Sa(e)}/payload${f?`?${f}`:""}`,{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error("Failed to fetch event payload");return d.json()},enabled:(t.enabled??!0)&&e!==void 0&&!!n})}function EY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.handlers(i),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/handlers",a),{headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch handlers");return l.json()},enabled:!!t&&!!n})}function TY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.prunePreview(i),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/prune/preview",a),{method:"POST",headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch prune preview");return l.json()},enabled:!!t&&!!n&&(e.enabled??!0)})}function CY(e={},t={}){const n=Vt(),{instanceId:s}=Lt(),i=e.instanceId??s,a=nf({limit:e.limit,offset:e.offset,operationType:e.operationType,partitionId:e.partitionId},i);return Wn({queryKey:Jn.operations({...e,instanceId:i}),queryFn:()=>{if(!n)throw new Error("Not connected");return Gu(n.GET("/console/operations",{params:{query:a}}))},enabled:(t.enabled??!0)&&!!n,refetchInterval:_i(t.refetchIntervalMs,1e4)})}function RY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async({clientId:i,partitionId:a,instanceId:l})=>{if(!e||!t)throw new Error("Not connected");const f=l??n,d=new URLSearchParams;a&&d.set("partitionId",a),f&&d.set("instanceId",f);const p=await fetch(Ln(t.serverUrl,`/console/clients/${Sa(i)}`,d),{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!p.ok)throw new Error("Failed to evict client");return p.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","clients"]}),s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function NY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=await fetch(Ln(t.serverUrl,"/console/prune",i),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!a.ok)throw new Error("Failed to prune");return a.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","commits"]}),s.invalidateQueries({queryKey:["console","timeline"]}),s.invalidateQueries({queryKey:["console","prune","preview"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function jY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=await fetch(Ln(t.serverUrl,"/console/compact",i),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!a.ok)throw new Error("Failed to compact");return a.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function AY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=i.instanceId??n,l=new URLSearchParams;a&&l.set("instanceId",a);const f=await fetch(Ln(t.serverUrl,"/console/notify-data-change",l),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({tables:i.tables,partitionId:i.partitionId})});if(!f.ok)throw new Error("Failed to notify data change");return f.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","stats"]}),s.invalidateQueries({queryKey:["console","commits"]}),s.invalidateQueries({queryKey:["console","timeline"]}),s.invalidateQueries({queryKey:["console","operations"]})}})}function kY(e={}){const t=Vt(),{config:n}=Dt(),{instanceId:s}=Lt(),i=e.instanceId??s;return Wn({queryKey:Jn.apiKeys({...e,instanceId:i}),queryFn:async()=>{if(!t||!n)throw new Error("Not connected");const a=new URLSearchParams;e.limit!==void 0&&a.set("limit",String(e.limit)),e.offset!==void 0&&a.set("offset",String(e.offset)),e.type&&a.set("type",e.type),e.status&&a.set("status",e.status),e.expiresWithinDays!==void 0&&a.set("expiresWithinDays",String(e.expiresWithinDays)),i&&a.set("instanceId",i);const l=await fetch(Ln(n.serverUrl,"/console/api-keys",a),{headers:{Authorization:`Bearer ${n.token}`}});if(!l.ok)throw new Error("Failed to fetch API keys");return l.json()},enabled:!!t&&!!n})}function OY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,"/console/api-keys",a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!l.ok)throw new Error("Failed to create API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function MY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}`,a),{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to revoke API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function IY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,"/console/api-keys/bulk-revoke",a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!l.ok)throw new Error("Failed to bulk revoke API keys");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function PY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}/rotate`,a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to rotate API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function DY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async i=>{if(!e||!t)throw new Error("Not connected");const a=new URLSearchParams;n&&a.set("instanceId",n);const l=await fetch(Ln(t.serverUrl,`/console/api-keys/${Sa(i)}/rotate/stage`,a),{method:"POST",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to stage-rotate API key");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","api-keys"]})}})}function zY(e={}){const{config:t}=Dt();return Wn({queryKey:Jn.storage({prefix:e.prefix,cursor:e.cursor,limit:e.limit}),queryFn:async()=>{if(!t)throw new Error("Not connected");const n=new URLSearchParams;e.prefix&&n.set("prefix",e.prefix),e.cursor&&n.set("cursor",e.cursor),e.limit&&n.set("limit",String(e.limit));const s=await fetch(Ln(t.serverUrl,"/console/storage",n),{method:"GET",headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok)throw new Error("Failed to list blobs");return s.json()},enabled:!!t,refetchInterval:_i(e.refetchIntervalMs,3e4)})}function LY(){const{config:e}=Dt(),t=_r();return os({mutationFn:async n=>{if(!e)throw new Error("Not connected");const s=encodeURIComponent(n),i=await fetch(Ln(e.serverUrl,`/console/storage/${s}`,new URLSearchParams),{method:"DELETE",headers:{Authorization:`Bearer ${e.token}`}});if(!i.ok)throw new Error("Failed to delete blob");return i.json()},onSuccess:()=>{t.invalidateQueries({queryKey:["console","storage"]})}})}function UY(){const{config:e}=Dt();return async t=>{if(!e)throw new Error("Not connected");const n=encodeURIComponent(t),s=await fetch(Ln(e.serverUrl,`/console/storage/${n}/download`,new URLSearchParams),{method:"GET",headers:{Authorization:`Bearer ${e.token}`}});if(!s.ok)throw new Error("Failed to download blob");const i=await s.blob(),a=URL.createObjectURL(i),l=document.createElement("a");l.href=a,l.download=t.split("/").pop()||t,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a)}}const $Y="console:partition-id";function sf(){const[e,t]=pi($Y,""),n=e.trim();return _.useMemo(()=>({partitionId:n.length>0?n:void 0,rawPartitionId:e,setPartitionId:t,clearPartitionId:()=>t("")}),[n,e,t])}const VC={refreshInterval:5,timeFormat:"relative",showSparklines:!0,pageSize:20};function of(){const[e,t]=pi("console:preferences",VC);return{preferences:e,setPreferences:t,updatePreference:(i,a)=>{t(l=>({...l,[i]:a}))},resetPreferences:()=>{t(VC)}}}const BY=[{value:5,label:"5 seconds"},{value:10,label:"10 seconds"},{value:30,label:"30 seconds"},{value:60,label:"1 minute"},{value:0,label:"Manual only"}],FY=[{value:10,label:"10"},{value:20,label:"20"},{value:50,label:"50"},{value:100,label:"100"}],gx="syncular-console-root";function HY(e){e.classList.add(gx)}const qY=[{suffix:"",label:"Command"},{suffix:"/stream",label:"Stream"},{suffix:"/fleet",label:"Fleet"},{suffix:"/ops",label:"Ops"},{suffix:"/storage",label:"Storage"},{suffix:"/config",label:"Config"}];function VY(e){const t=e?.trim()??"";return!t||t==="/"?"":(t.startsWith("/")?t:`/${t}`).replace(/\/+$/g,"")}function Uy(e,t){return e?t?`${e}${t}`:e:t||"/"}function GY({basePath:e,appHref:t,modeBadge:n}){const{connect:s,config:i,isConnected:a,isConnecting:l}=Dt(),{preferences:f}=of(),{instanceId:d,rawInstanceId:p,setInstanceId:g,clearInstanceId:y}=Lt(),{partitionId:b,rawPartitionId:x,setPartitionId:S,clearPartitionId:w}=sf(),T=vr({select:P=>P.location.pathname}),{data:C}=rf({refetchIntervalMs:f.refreshInterval*1e3,partitionId:b,instanceId:d}),O=VY(e),N=_.useMemo(()=>qY.map(P=>({...P,id:Uy(O,P.suffix)})),[O]),R=Uy(O,""),M=Uy(O,"/config"),z=l?"connecting":a?"connected":i?"disconnected":"not-configured",j=N.find(P=>P.suffix===""?T===R||T===`${R}/`:T.startsWith(P.id))?.id??R,A=C?[{label:"HEAD",value:`#${C.maxCommitSeq}`},{label:"COMMITS",value:`${C.commitCount}`},{label:"CHANGES",value:`${C.changeCount}`},{label:"CLIENTS",value:`${C.activeClientCount}/${C.clientCount}`}]:[];return h.jsxs("div",{className:`${gx} h-screen bg-background text-foreground flex flex-col`,children:[h.jsx(SZ,{brand:h.jsx(bc,{to:R,children:h.jsx(xZ,{label:"console"})}),center:h.jsx(hZ,{items:N,activeId:j,renderItem:(P,{active:Q})=>h.jsx(bc,{to:P.id,children:h.jsx(rk,{active:Q,children:P.label})},P.id)}),right:h.jsxs("div",{className:"flex items-center gap-2",children:[n?h.jsx(mn,{variant:"flow",className:"hidden md:inline-flex px-2 py-1 text-[10px]",children:n}):null,h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"font-mono text-[9px] text-neutral-500 uppercase tracking-wide",children:"Instance"}),h.jsx(Kn,{variant:"mono",value:p,onChange:P=>g(P.target.value),onBlur:P=>g(P.target.value.trim()),placeholder:"all",className:"h-7 w-[110px] px-2 py-1"}),d?h.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px]",onClick:y,children:"All"}):null]}),h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"font-mono text-[9px] text-neutral-500 uppercase tracking-wide",children:"Partition"}),h.jsx(Kn,{variant:"mono",value:x,onChange:P=>S(P.target.value),onBlur:P=>S(P.target.value.trim()),placeholder:"all",className:"h-7 w-[110px] px-2 py-1"}),b?h.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px]",onClick:w,children:"All"}):null]}),h.jsx(R8,{state:z}),h.jsx(bc,{to:M,children:h.jsx(Ne,{variant:T===M?"secondary":"ghost",size:"icon",children:h.jsx(mY,{className:"h-3 w-3"})})}),t?h.jsxs("a",{href:t,className:dZ,children:[h.jsx(hY,{className:"h-3 w-3"}),"Go to app"]}):null]})}),h.jsx("main",{className:"flex-1 overflow-auto pb-[32px]",children:h.jsx("div",{className:"min-h-full",children:a||T===M?h.jsx("div",{style:{animation:"pageIn 0.3s ease-out"},children:h.jsx(YN,{})},T):h.jsx(KY,{configPath:M,hasSavedConfig:!!i,isConnecting:l,onConnect:()=>{s()}})})}),a&&h.jsx(Bj,{isLive:a,metrics:A,uptime:"--"})]})}function KY({configPath:e,hasSavedConfig:t,isConnecting:n,onConnect:s}){return h.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[h.jsx("p",{className:"mb-4 text-foreground-muted",children:"Not connected to a @syncular server"}),h.jsxs("div",{className:"flex items-center gap-2",children:[t&&h.jsx(Ne,{variant:"default",onClick:s,disabled:n,children:n?"Connecting...":"Connect"}),h.jsx(bc,{to:e,children:h.jsx(Ne,{variant:"link",children:"Configure connection"})})]})]})}const uo=NH({component:GY});function ZY(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).get("swServer")==="1"}function YY(e={}){const{maxEvents:t=100,enabled:n=!0,staleAfterMs:s=65e3,replayLimit:i=100,partitionId:a,instanceId:l}=e,{config:f,isConnected:d}=Dt(),{instanceId:p}=Lt(),g=l??p,[y,b]=_.useState([]),[x,S]=_.useState(!1),[w,T]=_.useState("disconnected"),[C,O]=_.useState(null),N=_.useRef(null),R=_.useRef(null),M=_.useRef(null),z=_.useRef(0),j=_.useRef(0),A=_.useRef(null),P=_.useRef(null),Q=_.useCallback(()=>{b([]),A.current=null,P.current=null},[]);return _.useEffect(()=>{if(!n||!d||!f?.serverUrl||!f?.token)return;let B=!1;const U=Number.isFinite(i)?Math.max(1,Math.min(500,Math.floor(i))):100;if(ZY()||typeof WebSocket>"u"){T("connecting"),S(!1);let V=null,L=!1;const I=async()=>{if(!(B||L)){L=!0;try{const H=new URL(f.serverUrl,window.location.origin),W=H.pathname.endsWith("/")?H.pathname.slice(0,-1):H.pathname;H.pathname=`${W}/console/events`,H.search="",H.searchParams.set("limit",String(U)),H.searchParams.set("offset","0"),a&&H.searchParams.set("partitionId",a);const Y=await fetch(H.toString(),{headers:{Authorization:`Bearer ${f.token}`}});if(!Y.ok)throw new Error(`Live event polling failed (${Y.status})`);const ae=await Y.json(),fe=(Array.isArray(ae.items)?ae.items:[]).filter(Me=>g?Me.instanceId===g:!0).sort((Me,_e)=>Me.eventId-_e.eventId),Se=P.current??-1,pe=fe.filter(Me=>Me.eventId>Se);if(pe.length>0){const Me=pe.map(re=>({type:re.eventType,timestamp:re.createdAt,data:re})).reverse();b(re=>[...Me,...re].slice(0,t));const _e=pe[pe.length-1];P.current=_e.eventId,A.current=_e.createdAt}else if(fe.length>0){const Me=fe[fe.length-1];P.current=Math.max(P.current??-1,Me.eventId),A.current=Me.createdAt}O(null),S(!0),T("connected")}catch(H){B||(S(!1),T("disconnected"),O(H instanceof Error?H:new Error("Live event polling failed")))}finally{L=!1}}};return I(),V=setInterval(()=>{I()},2e3),()=>{B=!0,V&&clearInterval(V),S(!1),T("disconnected")}}const G=()=>{R.current&&(clearTimeout(R.current),R.current=null)},ee=()=>{M.current&&(clearInterval(M.current),M.current=null)},D=()=>{if(B||R.current)return;z.current+=1;const V=Math.min(3e4,1e3*2**Math.max(0,z.current-1)),L=Math.floor(V*.2*Math.random()),I=V+L;R.current=setTimeout(()=>{R.current=null,B||q()},I)},K=()=>{j.current=Date.now(),S(!0),T("connected")},q=()=>{if(B)return;T("connecting"),G();const V=(()=>{const I=new URL(f.serverUrl,window.location.origin);I.protocol=I.protocol==="https:"?"wss:":"ws:";const H=I.pathname.endsWith("/")?I.pathname.slice(0,-1):I.pathname;return I.pathname=`${H}/console/events/live`,I.search="",I.searchParams.set("token",f.token),A.current&&I.searchParams.set("since",A.current),I.searchParams.set("replayLimit",String(U)),a&&I.searchParams.set("partitionId",a),g&&I.searchParams.set("instanceId",g),I.toString()})(),L=new WebSocket(V);N.current=L,L.onopen=()=>{if(B){L.close();return}z.current=0,K(),O(null),ee(),M.current=setInterval(()=>{const I=N.current;if(!I||I.readyState!==WebSocket.OPEN)return;const H=j.current;!H||Date.now()-H<=s||(S(!1),T("stale"),I.close())},1e3)},L.onclose=()=>{B||(S(!1),T("disconnected"),ee(),D())},L.onerror=()=>{B||O(new Error("WebSocket connection failed"))},L.onmessage=I=>{try{const H=JSON.parse(I.data),W=H.type;if(K(),W==="connected"||W==="heartbeat")return;const Y={type:W,timestamp:H.timestamp||new Date().toISOString(),data:H};if(a&&Y.data.partitionId!==a||g&&Y.data.instanceId!==g)return;const ae=Date.parse(A.current??""),se=Date.parse(Y.timestamp);Number.isFinite(se)&&(!Number.isFinite(ae)||se>ae)&&(A.current=Y.timestamp),b(fe=>[Y,...fe].slice(0,t))}catch{}}};return q(),()=>{B=!0,G(),ee(),N.current&&(N.current.close(),N.current=null),S(!1),T("disconnected")}},[n,d,f?.serverUrl,f?.token,t,a,g,i,s]),{events:y,isConnected:x,connectionState:w,error:C,clearEvents:Q}}function XY(){const e=Vt(),{config:t}=Dt(),{instanceId:n}=Lt(),s=_r();return os({mutationFn:async()=>{if(!e||!t)throw new Error("Not connected");const i=new URLSearchParams;n&&i.set("instanceId",n);const a=i.toString(),l=await fetch(`${t.serverUrl}/console/events${a?`?${a}`:""}`,{method:"DELETE",headers:{Authorization:`Bearer ${t.token}`}});if(!l.ok)throw new Error("Failed to clear events");return l.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["console","events"]})}})}const QY=_.createContext(null);function mk(){const[e,t]=pi("console:time-range","24h");return{range:e,setRange:t}}const WY=[{hint:"ios",type:"mobile"},{hint:"android",type:"mobile"},{hint:"mobile",type:"mobile"},{hint:"tablet",type:"tablet"},{hint:"desktop",type:"desktop"},{hint:"mac",type:"desktop"},{hint:"windows",type:"desktop"},{hint:"linux",type:"desktop"},{hint:"browser",type:"browser"},{hint:"web",type:"browser"},{hint:"server",type:"server"},{hint:"api",type:"server"},{hint:"iot",type:"iot"},{hint:"sensor",type:"iot"}];function JY(e){const t=e.toLowerCase();for(const n of WY)if(t.includes(n.hint))return n.type;return"client"}function eX(e){const t=e.toLowerCase();return t.includes("pglite")?"PGlite":t.includes("sqlite")||t.includes("wa-sqlite")?"SQLite":t.includes("postgres")||t.includes("pg")?"PostgreSQL":"unknown"}function tX(e,t){return typeof e.lagCommitCount=="number"?Math.max(0,e.lagCommitCount):t?Math.max(0,t.maxCommitSeq-e.cursor):0}function nX(e,t){return e.activityState==="stale"?"offline":t>0?"syncing":"online"}function rX(e,t){return e.length<=16?e:`${e.slice(0,12)}-${t+1}`}function sX(e,t,n={}){const s=n.maxNodes??10;return e.slice(0,s).map((i,a)=>{const l=tX(i,t),f=nX(i,l);return{id:rX(i.clientId,a),type:JY(i.clientId),status:f,cursor:Math.max(0,i.cursor),actor:i.actorId,mode:i.connectionMode,dialect:eX(i.clientId),scopes:Object.keys(i.effectiveScopes||{}),lastSeen:i.updatedAt}})}const oX={enabled:!1,thresholds:{p90Latency:500,errorRate:5,clientLag:100}};function GC(e,t="relative"){if(t==="absolute")return new Date(e).toLocaleString();const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3);return a<60?`${a}s ago`:a<3600?`${Math.floor(a/60)}m ago`:a<86400?`${Math.floor(a/3600)}h ago`:`${Math.floor(a/86400)}d ago`}function iX(e){const t=e.length>1&&e.endsWith("/")?e.slice(0,-1):e;return t==="/console"||t.startsWith("/console/")?"/console/stream":"/stream"}function aX(){const e=dp(),t=_.useMemo(()=>typeof window>"u"?"/stream":iX(window.location.pathname),[]),n=mk(),{range:s}=n,{preferences:i}=of(),{partitionId:a}=sf(),l=i.refreshInterval*1e3,[f]=pi("console:alert-config",oX),[d,p]=_.useState("1h"),{data:g}=rf({refetchIntervalMs:l,partitionId:a}),{data:y}=yY({range:s,partitionId:a},{refetchIntervalMs:l}),{data:b}=vY({range:s,partitionId:a},{refetchIntervalMs:l}),{data:x}=bY({limit:5,partitionId:a},{refetchIntervalMs:l}),{data:S}=pk({limit:12,offset:0,partitionId:a},{refetchIntervalMs:l}),{events:w,isConnected:T}=YY({maxEvents:8,partitionId:a}),C=_.useMemo(()=>{const U=y?.buckets??[];let Z=0,G=0;for(const D of U)Z+=D.pushCount+D.pullCount,G+=D.errorCount;const ee=Z>0?G/Z*100:0;return{totalEvents:Z,errorRate:ee}},[y?.buckets]),O=_.useMemo(()=>S?.items?sX(S.items,g,{maxNodes:12}):[],[S?.items,g]),N=O.filter(U=>U.status!=="offline").length,R=O.filter(U=>U.status==="offline").length,M=_.useMemo(()=>g?[{label:"Ops (Range)",value:C.totalEvents,color:"flow"},{label:"P50 Latency",value:b?.push?.p50??0,unit:"ms",color:"healthy"},{label:"Error Rate",value:`${C.errorRate.toFixed(1)}%`,color:C.errorRate>0?"offline":"muted"},{label:"Active Clients",value:g.activeClientCount,color:"syncing"},{label:"Pending",value:g.maxActiveClientCursor!==null&&g.maxCommitSeq>0?g.maxCommitSeq-(g.minActiveClientCursor??0):0,color:"relay"}]:[],[g,b,C.errorRate,C.totalEvents]),z=_.useMemo(()=>w.map(U=>({type:U.type.toUpperCase(),actor:U.data?.actorId??"",table:(U.data?.tables??[])[0]??"",time:GC(U.timestamp,i.timeFormat)})),[w,i.timeFormat]),j=_.useMemo(()=>{const U=y?.buckets;if(!U?.length)return[];const Z=Math.max(...U.map(G=>Math.max(G.pushCount,G.pullCount)),1);return U.map(G=>({pushPercent:Z>0?G.pushCount/Z*100:0,pullPercent:Z>0?G.pullCount/Z*100:0}))},[y?.buckets]),A=_.useMemo(()=>{if(!b)return[];const U=Math.max(b.push.p50,b.push.p90,b.push.p99,b.pull.p50,b.pull.p90,b.pull.p99,1);return[{label:"P50",pushMs:b.push.p50,pullMs:b.pull.p50,pushBarPercent:b.push.p50/U*100,pullBarPercent:b.pull.p50/U*100},{label:"P90",pushMs:b.push.p90,pullMs:b.pull.p90,pushBarPercent:b.push.p90/U*100,pullBarPercent:b.pull.p90/U*100},{label:"P99",pushMs:b.push.p99,pullMs:b.pull.p99,pushBarPercent:b.push.p99/U*100,pullBarPercent:b.pull.p99/U*100}]},[b]),P=_.useMemo(()=>x?.items?x.items.map(U=>({seq:U.commitSeq,actor:U.actorId,changes:U.changeCount,tables:(U.affectedTables??[]).join(", "),time:GC(U.createdAt,i.timeFormat)})):[],[x?.items,i.timeFormat]),Q=_.useMemo(()=>Math.max(0,100-C.errorRate),[C.errorRate]),B=_.useMemo(()=>{if(!f.enabled||!g)return[];const U=[];return b?.push?.p90&&b.push.p90>f.thresholds.p90Latency&&U.push(`P90 push latency (${b.push.p90}ms) exceeds threshold (${f.thresholds.p90Latency}ms)`),g.minActiveClientCursor!==null&&g.maxCommitSeq-g.minActiveClientCursor>f.thresholds.clientLag&&U.push(`Client lag (${g.maxCommitSeq-g.minActiveClientCursor}) exceeds threshold (${f.thresholds.clientLag})`),C.errorRate>f.thresholds.errorRate&&U.push(`Error rate (${C.errorRate.toFixed(1)}%) exceeds threshold (${f.thresholds.errorRate}%)`),U},[f,g,b,C.errorRate]);return g?h.jsx(QY.Provider,{value:n,children:h.jsxs("div",{className:"flex flex-col",children:[B.length>0&&h.jsx("div",{className:"px-6 pb-4",children:h.jsxs(In,{variant:"destructive",children:[h.jsx(tf,{children:"Threshold Exceeded"}),h.jsx(Pn,{children:B.map((U,Z)=>h.jsx("span",{className:"block",children:U},Z))})]})}),h.jsx(zA,{clients:O,totalNodes:O.length+2,onlineCount:N,offlineCount:R,relayClientIds:[]}),h.jsx(Kj,{items:M}),h.jsxs("div",{className:"flex",children:[h.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[h.jsx("div",{className:"border-b border-border border-r border-border",children:h.jsx(xj,{bars:j,activeRange:d,onRangeChange:p})}),h.jsx("div",{className:"border-b border-border border-r border-border",children:h.jsx(Zj,{buckets:A,successRate:Q})}),h.jsx("div",{className:"border-r border-border",children:h.jsx(Fj,{commits:P,onViewAll:()=>e({href:t})})})]}),h.jsx(Yj,{entries:z,isConnected:T,maxVisible:20,maxHeight:"calc(100vh - 200px)"})]})]})}):h.jsx("div",{className:"flex items-center justify-center py-24",children:h.jsx(Pt,{size:"lg"})})}function cX(){return h.jsx(aX,{})}function lX({children:e}){return h.jsxs("div",{className:"space-y-4 px-5 py-5",children:[h.jsx(uX,{}),h.jsx(mX,{}),h.jsx(gX,{}),e]})}function uX(){const{clearError:e,config:t,connect:n,disconnect:s,error:i,isConnected:a,isConnecting:l}=Dt(),[f,d]=_.useState(t?.serverUrl??"/api"),[p,g]=_.useState(t?.token??""),[y,b]=_.useState(null),[x,S]=_.useState(!1),[w,T]=_.useState(null),[C,O]=pi("console:disconnect-clear-saved-config",!1);_.useEffect(()=>{const j=new URLSearchParams(window.location.search),A=j.get("token"),P=j.get("server");A&&(g(A),window.history.replaceState({},"",window.location.pathname)),P&&d(P)},[]),_.useEffect(()=>{t?.serverUrl&&d(t.serverUrl),t?.token&&g(t.token)},[t?.serverUrl,t?.token]),_.useEffect(()=>{T(null)},[]);const N=async()=>{e(),b(null);const j=await n({serverUrl:f.trim(),token:p.trim()},{persistOverride:!0});T(j?"Connected successfully and configuration saved.":"Failed to connect with the provided settings.")},R=()=>{s({clearSavedConfig:C}),C&&(d("/api"),g("")),T(C?"Disconnected and saved credentials cleared.":"Disconnected."),b(null)},M=async()=>{S(!0),b(null),T(null);const j=performance.now();try{const A=f.trim(),P=p.trim();if(!A||!P)throw new Error("Missing server URL or token");if(!(await fetch(`${A}/console/stats`,{headers:{Authorization:`Bearer ${P}`}})).ok)throw new Error("Failed to connect");b(Math.round(performance.now()-j))}catch{b(-1)}finally{S(!1)}},z=i??w??(y!==null?y<0?"Connection failed":`Connection successful (${y}ms latency)`:void 0);return h.jsx(Hj,{isConnected:a,isConnecting:l,isTestingConnection:x,serverUrl:f,onServerUrlChange:d,consoleToken:p,onConsoleTokenChange:g,onSaveAndConnect:N,onDisconnect:R,onTestConnection:M,statusMessage:z,children:h.jsx("div",{className:"px-5 pb-5 -mt-2",children:h.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2",children:[h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] text-neutral-400",children:"Clear saved credentials on disconnect"}),h.jsx("p",{className:"font-mono text-[9px] text-neutral-500",children:"Removes stored server URL and token from this browser."})]}),h.jsx(Sp,{checked:C,onCheckedChange:O})]})})})}const fX=1440*60*1e3;function KC(e){const t=e.trim();if(!t)return null;const n=Number.parseInt(t,10);return!Number.isInteger(n)||n<=0?null:n}function $y(e){if(!e)return"Never";const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():"Invalid date"}function dX(e){return e.length===0?"all scopes":e.length<=2?e.join(", "):`${e.slice(0,2).join(", ")} +${e.length-2}`}function hX(e,t){if(e.revokedAt)return"revoked";if(!e.expiresAt)return"active";const n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return"active";const s=Date.now();return n<=s?"expired":n<=s+t*fX?"expiring":"active"}function pX(e){return e==="revoked"?"destructive":e==="expired"?"offline":e==="expiring"?"syncing":"healthy"}function mX(){const[e,t]=_.useState("all"),[n,s]=_.useState("all"),[i,a]=_.useState("14"),[l,f]=_.useState(!1),[d,p]=_.useState(!1),[g,y]=_.useState(""),[b,x]=_.useState("relay"),[S,w]=_.useState(""),[T,C]=_.useState(""),[O,N]=_.useState(""),[R,M]=_.useState(null),[z,j]=_.useState([]),[A,P]=_.useState(null),[Q,B]=_.useState(null),[U,Z]=_.useState(null),[G,ee]=_.useState(null),[D,K]=_.useState(null),[q,V]=_.useState(null),[L,I]=_.useState(null),H=_.useMemo(()=>KC(i),[i]),W=H??14,Y=_.useMemo(()=>KC(O),[O]),ae=O.trim().length>0,se=!ae||Y!==null,fe=_.useMemo(()=>({type:e==="all"?void 0:e,status:n==="all"?void 0:n,expiresWithinDays:n==="expiring"?W:void 0}),[e,n,W]),{data:Se,isLoading:pe,error:Me}=kY(fe),_e=OY(),re=IY(),he=MY(),ie=PY(),we=DY();_.useEffect(()=>{const me=new Set((Se?.items??[]).map(Te=>Te.keyId));j(Te=>Te.filter(qe=>me.has(qe)))},[Se?.items]);const ye=async()=>{try{const me=T.split(",").map(qe=>qe.trim()).filter(qe=>qe.length>0),Te=await _e.mutateAsync({name:g,keyType:b,actorId:S||void 0,scopeKeys:me.length>0?me:void 0,expiresInDays:ae?Y??void 0:void 0});M(Te.secretKey),y(""),w(""),C(""),N("")}catch{}},xe=me=>{navigator.clipboard.writeText(me),B(me),setTimeout(()=>B(null),2e3)},ve=async()=>{if(U)try{await he.mutateAsync(U)}finally{Z(null)}},Ie=async()=>{if(z.length!==0)try{const me=await re.mutateAsync({keyIds:z});P(me),j([])}catch{}},Ue=async()=>{if(G)try{const me=await we.mutateAsync(G.keyId);K({oldKeyId:G.keyId,oldKeyName:G.name,secretKey:me.secretKey})}catch{}},Ee=async()=>{if(D)try{await he.mutateAsync(D.oldKeyId)}finally{K(null),ee(null)}},Ve=async()=>{if(q)try{const me=await ie.mutateAsync(q);I(me.secretKey)}finally{V(null)}};if(pe)return h.jsx("div",{className:"flex h-[200px] items-center justify-center",children:h.jsx(Pt,{size:"lg"})});if(Me)return h.jsx("div",{className:"flex h-[200px] items-center justify-center",children:h.jsxs("p",{className:"text-danger",children:["Failed to load API keys: ",Me.message]})});const Qe=(Se?.items??[]).filter(me=>me.revokedAt===null).map(me=>me.keyId),Be=Qe.length>0&&Qe.every(me=>z.includes(me)),We=z.length>0,He=(Se?.items??[]).filter(me=>z.includes(me.keyId)).map(me=>me.name);return h.jsxs(h.Fragment,{children:[h.jsxs(Wb,{title:"API Keys",description:"Issue, rotate, revoke, and audit key lifecycle state.",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs(Ne,{size:"sm",variant:"destructive",onClick:()=>p(!0),disabled:z.length===0,children:["Revoke Selected (",z.length,")"]}),h.jsx(Ne,{size:"sm",onClick:()=>f(!0),children:"Create Key"})]}),children:[h.jsxs("div",{className:"mb-4 grid gap-3 lg:grid-cols-3",children:[h.jsxs(ps,{children:[h.jsx(es,{children:"Type filter"}),h.jsxs(dh,{value:[e],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="all"||Te==="relay"||Te==="proxy"||Te==="admin")&&t(Te)},children:[h.jsx(Dr,{value:"all",children:"all"}),h.jsx(Dr,{value:"relay",children:"relay"}),h.jsx(Dr,{value:"proxy",children:"proxy"}),h.jsx(Dr,{value:"admin",children:"admin"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Status filter"}),h.jsxs(dh,{value:[n],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="all"||Te==="active"||Te==="revoked"||Te==="expiring")&&s(Te)},children:[h.jsx(Dr,{value:"all",children:"all"}),h.jsx(Dr,{value:"active",children:"active"}),h.jsx(Dr,{value:"revoked",children:"revoked"}),h.jsx(Dr,{value:"expiring",children:"expiring"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-expiring-window",children:"Expiring window (days)"}),h.jsx(pc,{children:"Used when status filter is set to expiring."}),h.jsx(Kn,{id:"api-key-expiring-window",placeholder:"14",value:i,inputMode:"numeric",onChange:me=>a(me.target.value)}),H===null&&i.trim().length>0?h.jsx("p",{className:"font-mono text-[10px] text-offline",children:"Enter a positive whole number."}):null]})]}),Se?.items.length===0?h.jsx(Qb,{message:"No API keys match the current filters."}):h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:h.jsx(Uv,{checked:Be,indeterminate:!Be&&We&&Qe.length>0,onCheckedChange:me=>{j(me?Qe:[])},"aria-label":"Select all active keys"})}),h.jsx(yt,{children:"NAME"}),h.jsx(yt,{children:"TYPE"}),h.jsx(yt,{children:"KEY PREFIX"}),h.jsx(yt,{children:"ACTOR"}),h.jsx(yt,{children:"SCOPES"}),h.jsx(yt,{children:"CREATED"}),h.jsx(yt,{children:"LAST USED"}),h.jsx(yt,{children:"EXPIRES"}),h.jsx(yt,{children:"STATUS"}),h.jsx(yt,{children:"ACTIONS"})]})}),h.jsx(Xu,{children:(Se?.items??[]).map(me=>{const Te=hX(me,W);return h.jsxs(io,{children:[h.jsx(vt,{children:h.jsx(Uv,{checked:z.includes(me.keyId),onCheckedChange:qe=>{j(ht=>qe?[...new Set([...ht,me.keyId])]:ht.filter(lt=>lt!==me.keyId))},"aria-label":`Select ${me.name}`,disabled:me.revokedAt!==null})}),h.jsx(vt,{className:"font-medium",children:me.name}),h.jsx(vt,{children:h.jsx(mn,{variant:me.keyType==="admin"?"flow":me.keyType==="proxy"?"ghost":"relay",children:me.keyType})}),h.jsx(vt,{children:h.jsxs("code",{className:"font-mono text-[11px]",children:[me.keyPrefix,"..."]})}),h.jsx(vt,{className:"text-neutral-500",children:me.actorId??"-"}),h.jsx(vt,{className:"max-w-[220px] text-neutral-500",children:h.jsx("code",{className:"font-mono text-[10px]",children:dX(me.scopeKeys)})}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.createdAt)}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.lastUsedAt)}),h.jsx(vt,{className:"text-neutral-500",children:$y(me.expiresAt)}),h.jsx(vt,{children:h.jsx(mn,{variant:pX(Te),children:Te})}),h.jsx(vt,{children:h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>ee(me),disabled:me.revokedAt!==null,children:"Stage"}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>V(me.keyId),disabled:me.revokedAt!==null,children:"Rotate"}),h.jsx(Ne,{variant:"destructive",size:"sm",onClick:()=>Z(me.keyId),disabled:me.revokedAt!==null,children:"Revoke"})]})})]},me.keyId)})})]})]}),h.jsx($r,{open:l,onOpenChange:f,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Create API Key"})}),R?h.jsx(ZC,{copiedKeyId:Q,onClose:()=>{M(null),f(!1)},onCopy:xe,secretKey:R,warning:"Copy this key now. You will not be able to view it again."}):h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-name",children:"Name"}),h.jsx(Kn,{id:"api-key-name",placeholder:"Backend Relay Key",value:g,onChange:me=>y(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Key type"}),h.jsxs(dh,{value:[b],multiple:!1,onValueChange:me=>{const Te=me.find(qe=>typeof qe=="string");(Te==="relay"||Te==="proxy"||Te==="admin")&&x(Te)},children:[h.jsx(Dr,{value:"relay",children:"relay"}),h.jsx(Dr,{value:"proxy",children:"proxy"}),h.jsx(Dr,{value:"admin",children:"admin"})]})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-actor-id",children:"Actor ID (optional)"}),h.jsx(pc,{children:"Pin this key to a fixed actor ID"}),h.jsx(Kn,{id:"api-key-actor-id",placeholder:"actor-123",value:S,onChange:me=>w(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-scope-keys",children:"Scope keys (optional)"}),h.jsx(pc,{children:"Comma-separated list of allowed scope keys"}),h.jsx(Kn,{id:"api-key-scope-keys",placeholder:"scope-a, scope-b",value:T,onChange:me=>C(me.target.value)})]}),h.jsxs(ps,{children:[h.jsx(es,{htmlFor:"api-key-expires-days",children:"Expires in days (optional)"}),h.jsx(pc,{children:"Leave empty to keep the key non-expiring."}),h.jsx(Kn,{id:"api-key-expires-days",placeholder:"30",value:O,inputMode:"numeric",onChange:me=>N(me.target.value)}),se?null:h.jsx("p",{className:"font-mono text-[10px] text-offline",children:"Enter a positive whole number."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>f(!1),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:ye,disabled:_e.isPending||!g||!se,children:_e.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Creating..."]}):"Create"})]})]})]})}),h.jsx($r,{open:d,onOpenChange:me=>{p(me),me||P(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Bulk Revoke API Keys"})}),A?h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[h.jsx(In,{variant:"destructive",children:h.jsxs(Pn,{children:["Requested ",A.requestedCount," keys. Revoked"," ",A.revokedCount,", already revoked"," ",A.alreadyRevokedCount,", not found"," ",A.notFoundCount,"."]})}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"primary",onClick:()=>{p(!1),P(null)},children:"Done"})})]}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:"This revokes selected keys immediately and cannot be undone."})}),h.jsxs("p",{className:"font-mono text-[10px] text-neutral-500",children:["Selected keys: ",He.slice(0,5).join(", "),He.length>5?` +${He.length-5} more`:""]})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>p(!1),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:Ie,disabled:re.isPending||z.length===0,children:re.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking..."]}):"Revoke Selected"})]})]})]})}),h.jsx($r,{open:G!==null||D!==null,onOpenChange:()=>{ee(null),K(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Stage Rotate API Key"})}),D?h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsx(In,{variant:"default",children:h.jsxs(Pn,{children:["Replacement key created for ",D.oldKeyName,". The old key is still active until you revoke it."]})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("code",{className:"flex-1 rounded-md border border-border bg-surface p-3 font-mono text-[11px] text-white break-all",children:D.secretKey}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>xe(D.secretKey),children:Q===D.secretKey?"Copied":"Copy"})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>{K(null),ee(null)},children:"Keep Old Key Active"}),h.jsx(Ne,{variant:"destructive",onClick:Ee,disabled:he.isPending,children:he.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking Old Key..."]}):"Finalize and Revoke Old Key"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"px-5 py-4",children:h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"Staged rotation creates a replacement key now and keeps the current key active until you explicitly revoke it."})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>ee(null),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:Ue,disabled:we.isPending||!G,children:we.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Staging..."]}):"Create Replacement Key"})]})]})]})}),h.jsx($r,{open:U!==null,onOpenChange:()=>Z(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Revoke API Key"})}),h.jsx("div",{className:"px-5 py-4",children:h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:"Revoking a key immediately invalidates it for all requests."})})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>Z(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:ve,disabled:he.isPending,children:he.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Revoking..."]}):"Revoke"})]})]})}),h.jsx($r,{open:q!==null||L!==null,onOpenChange:()=>{V(null),I(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Rotate API Key"})}),L?h.jsx(ZC,{copiedKeyId:Q,onClose:()=>I(null),onCopy:xe,secretKey:L,warning:"The previous key has been invalidated. Store this replacement securely."}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"px-5 py-4",children:h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"Rotating a key invalidates the previous secret immediately."})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>V(null),children:"Cancel"}),h.jsx(Ne,{variant:"primary",onClick:Ve,disabled:ie.isPending,children:ie.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Rotating..."]}):"Rotate"})]})]})]})})]})}function gX(){const{preferences:e,updatePreference:t,resetPreferences:n}=of(),s=[{type:"filter",label:"Auto-refresh interval",options:BY.map(i=>({id:`${i.value}`,label:i.label})),activeId:`${e.refreshInterval}`,onActiveChange:i=>t("refreshInterval",Number.parseInt(i,10))},{type:"filter",label:"Items per page",options:FY.map(i=>({id:`${i.value}`,label:i.label})),activeId:`${e.pageSize}`,onActiveChange:i=>t("pageSize",Number.parseInt(i,10))},{type:"filter",label:"Time format",options:[{id:"relative",label:"Relative"},{id:"absolute",label:"Absolute"}],activeId:e.timeFormat,onActiveChange:i=>t("timeFormat",i)},{type:"toggle",label:"Show sparklines",description:"Display mini trend charts in dashboard metric cards",checked:e.showSparklines,onCheckedChange:i=>t("showSparklines",i)}];return h.jsx(Xj,{rows:s,onResetDefaults:n})}function ZC({copiedKeyId:e,onClose:t,onCopy:n,secretKey:s,warning:i}){return h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:i})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("code",{className:"flex-1 rounded-md border border-border bg-surface p-3 font-mono text-[11px] text-white break-all",children:s}),h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>n(s),children:e===s?"Copied":"Copy"})]}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"primary",onClick:t,children:"Done"})})]})}function yX(e){const t=e.toLowerCase();return t.includes("mobile")||t.includes("ios")||t.includes("android")?"mobile":t.includes("tablet")?"tablet":t.includes("desktop")||t.includes("laptop")?"desktop":t.includes("edge")?"edge":t.includes("iot")?"iot":"desktop"}function vX(e){const t=e.toLowerCase();return t.includes("pglite")?"PGlite":t.includes("wa-sqlite")||t.includes("sqlite")?"SQLite":t.includes("postgres")||t.includes("pg")?"PostgreSQL":"unknown"}function bX(e,t){if(t==="absolute")return new Date(e).toLocaleString();try{const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3),l=Math.floor(a/60),f=Math.floor(l/60),d=Math.floor(f/24);return a<60?"just now":l<60?`${l}m ago`:f<24?`${f}h ago`:`${d}d ago`}catch{return e}}function xX(e,t,n){return{id:e.clientId,type:yX(e.clientId),status:e.activityState==="stale"?"offline":e.activityState==="idle"?"syncing":"online",cursor:e.cursor,actor:e.actorId,mode:e.connectionMode==="realtime"?"realtime":"polling",dialect:vX(e.clientId),scopes:Object.keys(e.effectiveScopes??{}),lastSeen:bX(e.updatedAt,n)}}function SX({emptyState:e}={}){const[t,n]=_.useState(1),[s,i]=_.useState(null),{preferences:a}=of(),{partitionId:l}=sf(),f=a.pageSize,d=a.refreshInterval*1e3,{data:p,isLoading:g}=rf({refetchIntervalMs:d,partitionId:l}),{data:y,isLoading:b,error:x}=pk({limit:f,offset:(t-1)*f,partitionId:l},{refetchIntervalMs:d}),S=RY(),w=Math.ceil((y?.total??0)/f),T=p?.maxCommitSeq??0;_.useEffect(()=>{n(1)},[]);const C=async()=>{if(s)try{await S.mutateAsync({clientId:s,partitionId:l})}finally{i(null)}};if(b||g)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});if(x)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger",children:["Failed to load clients: ",x.message]})});const O=(y?.items??[]).map(N=>xX(N,T,a.timeFormat));return h.jsxs("div",{className:"flex flex-col gap-5 px-5 py-5",children:[O.length>0&&h.jsx(Wj,{clients:O,headSeq:T}),O.length===0?e??h.jsx(F8,{children:h.jsx(Qb,{message:"No clients yet"})}):h.jsx(Vj,{clients:O,headSeq:T,onEvict:N=>{const R=y?.items.find(M=>M.clientId===N);i(R?.clientId??N)}}),w>1&&h.jsx(px,{page:t,totalPages:w,totalItems:y?.total??0,onPageChange:n}),h.jsx($r,{open:s!==null,onOpenChange:()=>i(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Evict Client"})}),h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs("p",{className:"font-mono text-[11px] text-neutral-300",children:["Are you sure you want to evict client"," ",h.jsxs("span",{className:"font-mono text-white",children:[s?.slice(0,12),"..."]}),"?"]}),h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"This will force the client to re-bootstrap on their next sync."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>i(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:C,disabled:S.isPending,children:S.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Evicting..."]}):"Evict"})]})]})})]})}const _X={latencyThresholdMs:1e3,errorRateThreshold:5,clientLagThreshold:50,enabled:!1};function wX(e){return e<1e3?`${e}ms`:e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function EX(e){const t=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);return Array.from(new Set(t))}function TX(e){switch(e){case"notify_data_change":return"Notify";case"evict_client":return"Evict";case"compact":return"Compact";default:return"Prune"}}function YC(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function CX(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function RX(e){const t=YC(e.requestPayload),n=YC(e.resultPayload);if(e.operationType==="notify_data_change"){const a=CX(t?.tables),l=n?.commitSeq;return`${a.length} table${a.length===1?"":"s"} -> commit #${typeof l=="number"?l:"?"}`}if(e.operationType==="evict_client"){const a=n?.evicted===!0?"evicted":"not found";return`client ${e.targetClientId??"?"} ${a}`}if(e.operationType==="compact")return`${typeof n?.deletedChanges=="number"?n.deletedChanges:0} changes removed`;const s=typeof n?.deletedCommits=="number"?n.deletedCommits:0,i=typeof t?.watermarkCommitSeq=="number"?` at #${t.watermarkCommitSeq}`:"";return`${s} commits removed${i}`}function NX(e){const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function jX(){const{partitionId:e}=sf();return h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-5",children:[h.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[h.jsx(AX,{}),h.jsx(PX,{})]}),h.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[h.jsx(kX,{partitionId:e}),h.jsx(OX,{partitionId:e}),h.jsx(MX,{partitionId:e})]}),h.jsx(IX,{partitionId:e})]})}function AX(){const{data:e,isLoading:t,error:n}=EY();if(t)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});if(n)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger",children:["Failed to load handlers: ",n.message]})});const s=(e?.items??[]).map(i=>({table:i.table,dependsOn:i.dependsOn?.join(", ")??null,chunkTtl:i.snapshotChunkTtlMs?wX(i.snapshotChunkTtlMs):"default"}));return h.jsx(Gj,{handlers:s,tableCount:e?.items.length??0})}function kX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState(null),{data:a,isLoading:l}=rf({partitionId:e}),{data:f,isLoading:d,refetch:p}=TY({enabled:!1}),g=NY(),y=async()=>{n(!0),i(null),await p()},b=async()=>{const S=await g.mutateAsync();i(S.deletedCommits)};if(l)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});const x=[{label:"Total commits",value:a?.commitCount??0},{label:"Commit range",value:`${a?.minCommitSeq??0} - ${a?.maxCommitSeq??0}`},{label:"Min active cursor",value:a?.minActiveClientCursor??"N/A",tone:"syncing"}];return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Prune",description:"Delete commits that all clients have already synced. Pruning removes commits older than the oldest active client cursor.",dotColor:"syncing",stats:x,actionLabel:"Preview Prune",actionVariant:"destructive",onAction:y}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Prune Old Commits"})}),h.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:s!==null?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Pruning Complete"}),h.jsxs(Pn,{children:["Successfully deleted ",h.jsx("strong",{children:s})," commits."]})]}):d?h.jsx("div",{className:"flex items-center justify-center py-8",children:h.jsx(Pt,{size:"sm"})}):f?h.jsxs(h.Fragment,{children:[h.jsx(In,{variant:f.commitsToDelete>0?"destructive":"default",children:h.jsx(Pn,{children:f.commitsToDelete>0?h.jsxs(h.Fragment,{children:["This will delete"," ",h.jsx("strong",{children:f.commitsToDelete})," commits up to sequence"," ",h.jsxs("code",{className:"font-mono",children:["#",f.watermarkCommitSeq]}),"."]}):"No commits are eligible for pruning."})}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex justify-between font-mono text-[11px]",children:[h.jsx("span",{className:"text-neutral-500",children:"Watermark commit seq:"}),h.jsxs("span",{className:"text-white",children:["#",f.watermarkCommitSeq]})]}),h.jsxs("div",{className:"flex justify-between font-mono text-[11px] items-center",children:[h.jsx("span",{className:"text-neutral-500",children:"Commits to delete:"}),h.jsx(mn,{variant:f.commitsToDelete>0?"offline":"ghost",children:f.commitsToDelete})]})]})]}):null}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:s!==null?"Close":"Cancel"}),s===null&&h.jsx(Ne,{variant:"destructive",onClick:b,disabled:g.isPending||d||(f?.commitsToDelete??0)===0,children:g.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Pruning..."]}):"Prune Now"})]})]})})]})}function OX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState(null),{data:a,isLoading:l}=rf({partitionId:e}),f=jY(),d=()=>{n(!0),i(null)},p=async()=>{const y=await f.mutateAsync();i(y.deletedChanges)};if(l)return h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})});const g=[{label:"Total changes",value:a?.changeCount??0},{label:"Total commits",value:a?.commitCount??0}];return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Compact",description:"Merge old changes to reduce storage space. Compaction merges multiple changes to the same row into a single change.",dotColor:"flow",stats:g,actionLabel:"Run Compaction",actionVariant:"primary",onAction:d}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Compact Changes"})}),h.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:s!==null?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Compaction Complete"}),h.jsxs(Pn,{children:["Successfully removed ",h.jsx("strong",{children:s})," redundant changes."]})]}):h.jsx(In,{variant:"default",children:h.jsx(Pn,{children:"Compaction will merge multiple changes to the same row, keeping only the most recent version. This is safe and can be run at any time."})})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:s!==null?"Close":"Cancel"}),s===null&&h.jsx(Ne,{variant:"primary",onClick:p,disabled:f.isPending,children:f.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Compacting..."]}):"Compact Now"})]})]})})]})}function MX({partitionId:e}){const[t,n]=_.useState(!1),[s,i]=_.useState("tasks"),[a,l]=_.useState(e??""),[f,d]=_.useState(null),[p,g]=_.useState(null),y=AY(),b=EX(s),x=[{label:"Next tables",value:b.length,tone:"syncing"},{label:"Last commit seq",value:f?`#${f.commitSeq}`:"—",tone:"syncing"},{label:"Last chunks cleared",value:f?.deletedChunks??"—"}],S=()=>{n(!0),g(null)},w=async()=>{if(b.length===0){g("Provide at least one table name.");return}g(null);const T=await y.mutateAsync({tables:b,partitionId:a.trim()||void 0});d(T)};return h.jsxs(h.Fragment,{children:[h.jsx(_p,{title:"Notify Data Change",description:"Create a synthetic commit after external imports or direct DB writes so clients re-bootstrap for affected tables.",dotColor:"healthy",stats:x,actionLabel:"Notify Clients",actionVariant:"primary",onAction:S}),h.jsx($r,{open:t,onOpenChange:n,children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Notify External Data Change"})}),h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-4",children:[f?h.jsxs(In,{variant:"default",children:[h.jsx(tf,{children:"Notification Sent"}),h.jsxs(Pn,{children:["Created synthetic commit"," ",h.jsxs("strong",{children:["#",f.commitSeq]})," for"," ",h.jsx("strong",{children:f.tables.length})," table",f.tables.length===1?"":"s"," and cleared"," ",h.jsx("strong",{children:f.deletedChunks})," cached chunk",f.deletedChunks===1?"":"s","."]})]}):h.jsx(In,{variant:"default",children:h.jsx(Pn,{children:"Use this when data changed outside Syncular push flow. It invalidates cached snapshot chunks and forces clients to pull fresh data."})}),p?h.jsx(In,{variant:"destructive",children:h.jsx(Pn,{children:p})}):null,h.jsxs(ps,{children:[h.jsx(es,{children:"Tables (comma-separated)"}),h.jsx(Kn,{value:s,onChange:T=>i(T.target.value),placeholder:"tasks, notes",disabled:y.isPending}),h.jsx(pc,{children:"Enter one or more table names affected by the external change."})]}),h.jsxs(ps,{children:[h.jsx(es,{children:"Partition ID (optional)"}),h.jsx(Kn,{value:a,onChange:T=>l(T.target.value),placeholder:"default",disabled:y.isPending})]})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>n(!1),children:f?"Close":"Cancel"}),f?null:h.jsx(Ne,{variant:"primary",onClick:w,disabled:y.isPending,children:y.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"}),"Notifying..."]}):"Notify Data Change"})]})]})})]})}function IX({partitionId:e}){const[t,n]=_.useState("all"),{data:s,isLoading:i,error:a}=CY({limit:20,offset:0,operationType:t==="all"?void 0:t,partitionId:e},{refetchIntervalMs:5e3});return h.jsx(Wb,{title:"Operation Audit",description:"Recent prune/compact/notify/evict actions with actor and result context.",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Ne,{variant:t==="all"?"default":"ghost",size:"sm",onClick:()=>n("all"),children:"All"}),h.jsx(Ne,{variant:t==="prune"?"default":"ghost",size:"sm",onClick:()=>n("prune"),children:"Prune"}),h.jsx(Ne,{variant:t==="compact"?"default":"ghost",size:"sm",onClick:()=>n("compact"),children:"Compact"}),h.jsx(Ne,{variant:t==="notify_data_change"?"default":"ghost",size:"sm",onClick:()=>n("notify_data_change"),children:"Notify"}),h.jsx(Ne,{variant:t==="evict_client"?"default":"ghost",size:"sm",onClick:()=>n("evict_client"),children:"Evict"})]}),contentClassName:"pt-2",children:i?h.jsx("div",{className:"flex items-center justify-center py-10",children:h.jsx(Pt,{size:"lg"})}):a?h.jsx(In,{variant:"destructive",children:h.jsxs(Pn,{children:["Failed to load operation audit events: ",a.message]})}):(s?.items.length??0)===0?h.jsx("div",{className:"px-2 py-8 text-sm text-neutral-500",children:"No operation events found for this filter."}):h.jsx("div",{className:"overflow-x-auto",children:h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:"Time"}),h.jsx(yt,{children:"Type"}),h.jsx(yt,{children:"User"}),h.jsx(yt,{children:"Target"}),h.jsx(yt,{children:"Result"})]})}),h.jsx(Xu,{children:(s?.items??[]).map((l,f)=>h.jsxs(io,{children:[h.jsx(vt,{className:"whitespace-nowrap text-xs text-neutral-400",children:NX(l.createdAt)}),h.jsx(vt,{children:h.jsx(mn,{variant:"ghost",children:TX(l.operationType)})}),h.jsx(vt,{className:"font-mono text-xs",children:l.consoleUserId??"system"}),h.jsx(vt,{className:"font-mono text-xs",children:l.targetClientId??l.partitionId??(l.operationType==="notify_data_change"?"partition default":"global")}),h.jsx(vt,{className:"font-mono text-xs text-neutral-300",children:RX(l)})]},`${l.operationId}:${l.createdAt}:${f}`))})]})})})}function PX(){const[e,t]=pi("console:alert-config",_X),n={p90Latency:e.latencyThresholdMs,errorRate:e.errorRateThreshold,clientLag:e.clientLagThreshold},s=a=>{t(l=>({...l,latencyThresholdMs:a.p90Latency,errorRateThreshold:a.errorRate,clientLagThreshold:a.clientLag}))},i=a=>{t(l=>({...l,enabled:a}))};return h.jsx(Uj,{enabled:e.enabled,onEnabledChange:i,thresholds:n,onThresholdsChange:s})}function DX(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n===0?0:1)} ${t[n]}`}function zX(e){const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function LX(){const[e,t]=_.useState(""),[n,s]=_.useState(void 0),[i,a]=_.useState(void 0),[l,f]=_.useState([]),[d,p]=_.useState(null),{data:g,isLoading:y,error:b}=zY({prefix:n,cursor:i,limit:100}),x=LY(),S=UY();function w(){const M=e.trim();s(M.length>0?M:void 0),a(void 0),f([])}function T(){t(""),s(void 0),a(void 0),f([])}function C(){g?.cursor&&(f(M=>[...M,i??""]),a(g.cursor))}function O(){f(M=>{const z=[...M],j=z.pop();return a(j&&j.length>0?j:void 0),z})}function N(){d&&x.mutate(d,{onSuccess:()=>p(null)})}if(y)return h.jsx("div",{className:"flex flex-col gap-4 px-5 py-5",children:h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsx(Pt,{size:"lg"})})});if(b)return h.jsx("div",{className:"flex flex-col gap-4 px-5 py-5",children:h.jsx("div",{className:"flex items-center justify-center h-[200px]",children:h.jsxs("p",{className:"text-danger font-mono text-[11px]",children:["Failed to load storage items: ",b.message]})})});const R=g?.items??[];return h.jsxs("div",{className:"flex flex-col gap-4 px-5 py-5",children:[h.jsx(Wb,{title:"Storage",actions:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Kn,{placeholder:"Prefix filter...",value:e,onChange:M=>t(M.target.value),onKeyDown:M=>{M.key==="Enter"&&w()},className:"h-7 w-48 text-xs"}),h.jsx(Ne,{variant:"default",size:"sm",onClick:w,children:"Filter"}),n&&h.jsx(Ne,{variant:"ghost",size:"sm",onClick:T,children:"Clear"})]}),children:R.length===0?h.jsx(Qb,{message:n?`No storage items matching prefix "${n}".`:"No storage items found."}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"overflow-x-auto",children:h.jsxs(Zu,{children:[h.jsx(Yu,{children:h.jsxs(io,{children:[h.jsx(yt,{children:"Key"}),h.jsx(yt,{children:"Size"}),h.jsx(yt,{children:"Type"}),h.jsx(yt,{children:"Uploaded"}),h.jsx(yt,{children:"Actions"})]})}),h.jsx(Xu,{children:R.map(M=>h.jsxs(io,{children:[h.jsx(vt,{className:"font-mono text-xs max-w-[320px]",title:M.key,children:M.key}),h.jsx(vt,{className:"font-mono text-xs text-neutral-400 whitespace-nowrap",children:DX(M.size)}),h.jsx(vt,{children:M.httpMetadata?.contentType?h.jsx(mn,{variant:"ghost",children:M.httpMetadata.contentType}):h.jsx("span",{className:"text-neutral-500 text-xs",children:"--"})}),h.jsx(vt,{className:"whitespace-nowrap text-xs text-neutral-400",children:zX(M.uploaded)}),h.jsx(vt,{children:h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>{S(M.key)},children:"Download"}),h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>p(M.key),children:"Delete"})]})})]},M.key))})]})}),h.jsxs("div",{className:"flex items-center justify-between px-2 py-2",children:[h.jsx(Ne,{variant:"ghost",size:"sm",disabled:l.length===0,onClick:O,children:"Previous"}),h.jsx(Ne,{variant:"ghost",size:"sm",disabled:!g?.truncated,onClick:C,children:"Next"})]})]})}),h.jsx($r,{open:d!==null,onOpenChange:()=>p(null),children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Delete Storage Item"})}),h.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[h.jsxs("p",{className:"font-mono text-[11px] text-neutral-300",children:["Are you sure you want to delete"," ",h.jsx("span",{className:"font-mono text-white",children:d}),"?"]}),h.jsx("p",{className:"font-mono text-[10px] text-neutral-500",children:"This action cannot be undone."})]}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",onClick:()=>p(null),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",onClick:N,disabled:x.isPending,children:x.isPending?h.jsxs(h.Fragment,{children:[h.jsx(Pt,{size:"sm"})," Deleting..."]}):"Delete"})]})]})})]})}const UX={};function su(e,t){if(t==="absolute")return new Date(e).toLocaleString();const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3);return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m`:a<86400?`${Math.floor(a/3600)}h`:`${Math.floor(a/86400)}d`}function $X(e){const t=e.split(/\s+/).map(i=>i.trim()).filter(i=>i.length>0),n={},s=[];for(const i of t){const[a="",...l]=i.split(":"),f=l.join(":").trim(),d=a.toLowerCase();if(!f){s.push(i);continue}if(d==="actor"){n.actorId=f;continue}if(d==="client"){n.clientId=f;continue}if(d==="table"){n.table=f;continue}if(d==="request"){n.requestId=f;continue}if(d==="trace"){n.traceId=f;continue}s.push(i)}return s.length>0&&(n.search=s.join(" ")),n}function BX(e){return e==="1h"?3600*1e3:e==="6h"?360*60*1e3:e==="24h"?1440*60*1e3:e==="7d"?10080*60*1e3:720*60*60*1e3}function Kd(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function FX(e,t){return e?`#${e.federatedCommitId??(t?`${t}:${e.commitSeq}`:String(e.commitSeq))}`:"#?"}function HX(e,t){return e?`E${e.federatedEventId??(t?`${t}:${e.eventId}`:e.eventId)}`:"E?"}function qX(e,t,n){return!e||!t?null:e.replaceAll("{traceId}",encodeURIComponent(t)).replaceAll("{spanId}",encodeURIComponent(n??""))}function yx({initialSelectedEntryId:e}={}){const{preferences:t}=of(),{partitionId:n}=sf(),{range:s,setRange:i}=mk(),a=t.pageSize,l=t.refreshInterval*1e3,f=UX?.VITE_CONSOLE_TRACE_URL_TEMPLATE,[d,p]=_.useState(()=>e?.startsWith("#")?"commits":e?.startsWith("E")?"events":"all"),[g,y]=_.useState("all"),[b,x]=_.useState("all"),[S,w]=_.useState(""),[T,C]=_.useState(1),[O,N]=_.useState(!1),[R,M]=_.useState(e??null),z=_.useRef(!1),j=_.useMemo(()=>$X(S),[S]),A=_.useMemo(()=>new Date(Date.now()-BX(s)).toISOString(),[s]),{data:P,isLoading:Q,refetch:B}=SY({limit:a,offset:(T-1)*a,...n?{partitionId:n}:{},view:d,...d!=="commits"&&g!=="all"?{eventType:g}:{},...d!=="commits"&&b!=="all"?{outcome:b}:{},...j.actorId?{actorId:j.actorId}:{},...j.clientId?{clientId:j.clientId}:{},...j.requestId?{requestId:j.requestId}:{},...j.traceId?{traceId:j.traceId}:{},...j.table?{table:j.table}:{},...j.search?{search:j.search}:{},from:A},{refetchIntervalMs:l}),U=XY(),Z=R?.startsWith("#")?R.slice(1):void 0,G=R?.startsWith("E")?R.slice(1):void 0,ee=Z&&Z!=="?"?Z:void 0,D=G&&G!=="?"?G:void 0,{data:K,isLoading:q,error:V}=xY(ee,{enabled:ee!==void 0,partitionId:n}),{data:L,isLoading:I,error:H}=_Y(D,{enabled:D!==void 0,partitionId:n}),{data:W,isLoading:Y,error:ae}=wY(D,{enabled:D!==void 0&&!!L?.payloadRef,partitionId:n}),se=_.useMemo(()=>qX(f,L?.traceId??null,L?.spanId??null),[L?.spanId,L?.traceId,f]);_.useEffect(()=>{C(1)},[]),_.useEffect(()=>{C(1)},[]),_.useEffect(()=>{e&&M(e)},[e]),_.useEffect(()=>{if(!z.current){z.current=!0;return}M(null)},[]),_.useEffect(()=>{C(1),M(null)},[]);const Se=_.useMemo(()=>(P?.items??[]).map(we=>{const ye=we.instanceId??we.commit?.instanceId??we.event?.instanceId,xe=ye?`[${ye}] `:"";if(we.type==="commit"&&we.commit){const Ie=we.commit;return{type:"commit",id:FX(Ie,ye),outcome:"--",duration:"--",actor:Ie.actorId,client:Ie.clientId,detail:`${xe}${Ie.changeCount} chg | ${(Ie.affectedTables??[]).join(", ")}`,time:su(we.timestamp,t.timeFormat)}}const ve=we.event;return ve?{type:ve.eventType,id:HX(ve,ye),outcome:ve.outcome,duration:`${ve.durationMs}ms`,actor:ve.actorId,client:ve.clientId,detail:`${xe}${(ve.tables??[]).join(", ")||"--"}`,time:su(we.timestamp,t.timeFormat)}:{type:"pull",id:"E?",outcome:"unknown",duration:"--",actor:"",client:"",detail:"--",time:su(we.timestamp,t.timeFormat)}}),[t.timeFormat,P?.items]),pe=P?.total??0,Me=Math.max(1,Math.ceil(pe/a)),_e=Q,re=[{label:"",options:[{id:"all",label:"All"},{id:"commits",label:"Commits"},{id:"events",label:"Events"}],activeId:d,onActiveChange:ie=>{p(ie),ie==="commits"&&(y("all"),x("all")),C(1)}},{label:"Time",options:[{id:"1h",label:"1h"},{id:"6h",label:"6h"},{id:"24h",label:"24h"},{id:"7d",label:"7d"},{id:"30d",label:"30d"}],activeId:s,onActiveChange:ie=>{i(ie),C(1)}},{label:"Type",options:[{id:"all",label:"All"},{id:"push",label:"Push"},{id:"pull",label:"Pull"}],activeId:g,onActiveChange:ie=>{y(ie),C(1)}},{label:"Outcome",options:[{id:"all",label:"All"},{id:"applied",label:"Applied"},{id:"error",label:"Error"},{id:"rejected",label:"Rejected"}],activeId:b,onActiveChange:ie=>{x(ie),C(1)}}];function he(){U.mutate(void 0,{onSuccess:()=>{N(!1),B()}})}return h.jsxs("div",{className:"flex flex-col h-full",children:[_e&&Se.length===0?h.jsx("div",{className:"flex items-center justify-center py-24",children:h.jsx(Pt,{size:"lg"})}):h.jsx(Qj,{entries:Se,selectedEntryId:R,onEntryClick:ie=>M(ie.id),filterBar:h.jsx(qj,{groups:re,searchValue:S,searchPlaceholder:"Use actor:, client:, table:, request:, trace: or free text...",onSearchChange:w,actions:h.jsxs(h.Fragment,{children:[h.jsx(Ne,{size:"sm",variant:"ghost",onClick:()=>{B()},children:"Refresh"}),h.jsx(Ne,{size:"sm",variant:"ghost",children:"Export"}),h.jsx(Ne,{size:"sm",variant:"destructive",onClick:()=>N(!0),children:"Clear"})]})}),pagination:h.jsx(px,{page:T,totalPages:Me,totalItems:pe,onPageChange:C})}),h.jsx($r,{open:R!==null,onOpenChange:ie=>{ie||M(null)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:ee!==void 0?`Commit #${ee}`:D!==void 0?`Event E${D}`:"Entry details"})}),h.jsx("div",{className:"px-5 py-4 space-y-3 max-h-[70vh] overflow-y-auto",children:q||I?h.jsx("div",{className:"flex items-center justify-center py-8",children:h.jsx(Pt,{size:"sm"})}):V||H?h.jsx("p",{className:"font-mono text-[11px] text-offline",children:"Failed to load details."}):K?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"grid grid-cols-2 gap-3 font-mono text-[11px]",children:[h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Actor"}),h.jsx("div",{className:"text-neutral-100",children:K.actorId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Client"}),h.jsx("div",{className:"text-neutral-100",children:K.clientId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Instance"}),h.jsx("div",{className:"text-neutral-100",children:K.instanceId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Created"}),h.jsx("div",{className:"text-neutral-100",children:su(K.createdAt,t.timeFormat)})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Changes"}),h.jsx("div",{className:"text-neutral-100",children:K.changeCount})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Affected Tables"}),h.jsx("p",{className:"font-mono text-[11px] text-neutral-200",children:K.affectedTables.join(", ")||"--"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Changes"}),K.changes.length===0?h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No changes recorded."}):K.changes.map(ie=>h.jsxs("div",{className:"rounded-md border border-border p-3 space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between font-mono text-[11px]",children:[h.jsxs("span",{className:"text-neutral-300",children:[ie.table," | ",ie.op]}),h.jsxs("span",{className:"text-neutral-500",children:["#",ie.changeId]})]}),h.jsxs("div",{className:"font-mono text-[11px] text-neutral-400",children:["rowId: ",ie.rowId,ie.rowVersion!==null?` | version: ${ie.rowVersion}`:""]}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(ie.rowJson)})]},ie.changeId))]})]}):L?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"grid grid-cols-2 gap-3 font-mono text-[11px]",children:[h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Type"}),h.jsx("div",{className:"text-neutral-100",children:L.eventType})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Path"}),h.jsx("div",{className:"text-neutral-100",children:L.syncPath})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Instance"}),h.jsx("div",{className:"text-neutral-100",children:L.instanceId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Outcome"}),h.jsx("div",{className:"text-neutral-100",children:L.outcome})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Response Status"}),h.jsx("div",{className:"text-neutral-100",children:L.responseStatus})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Actor"}),h.jsx("div",{className:"text-neutral-100",children:L.actorId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Client"}),h.jsx("div",{className:"text-neutral-100",children:L.clientId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Status"}),h.jsx("div",{className:"text-neutral-100",children:L.statusCode})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Transport"}),h.jsx("div",{className:"text-neutral-100",children:L.transportPath})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Duration"}),h.jsxs("div",{className:"text-neutral-100",children:[L.durationMs,"ms"]})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Request ID"}),h.jsx("div",{className:"text-neutral-100",children:L.requestId})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Trace ID"}),h.jsx("div",{className:"text-neutral-100",children:L.traceId??"--"}),se&&h.jsx("a",{href:se,target:"_blank",rel:"noreferrer",className:"font-mono text-[10px] text-flow underline underline-offset-4",children:"Open external trace"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Span ID"}),h.jsx("div",{className:"text-neutral-100",children:L.spanId??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Commit Seq"}),h.jsx("div",{className:"text-neutral-100",children:L.commitSeq??"--"}),L.commitSeq!==null&&h.jsx(Ne,{variant:"ghost",size:"sm",onClick:()=>M(`#${L.instanceId?`${L.instanceId}:`:""}${L.commitSeq}`),children:"Open linked commit"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Subscription Count"}),h.jsx("div",{className:"text-neutral-100",children:L.subscriptionCount??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Error Code"}),h.jsx("div",{className:"text-neutral-100",children:L.errorCode??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Payload Ref"}),h.jsx("div",{className:"text-neutral-100",children:L.payloadRef??"--"})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-neutral-500",children:"Created"}),h.jsx("div",{className:"text-neutral-100",children:su(L.createdAt,t.timeFormat)})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Tables"}),h.jsx("p",{className:"font-mono text-[11px] text-neutral-200",children:L.tables.join(", ")||"--"})]}),L.scopesSummary&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Scopes Summary"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(L.scopesSummary)})]}),L.payloadRef&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Payload Snapshot"}),Y?h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Pt,{size:"sm"}),h.jsx("span",{className:"font-mono text-[11px] text-neutral-400",children:"Loading payload snapshot..."})]}):ae?h.jsx("p",{className:"font-mono text-[11px] text-offline",children:"Failed to load payload snapshot."}):W?h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Request"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(W.requestPayload)}),h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500",children:"Response"}),h.jsx("pre",{className:"font-mono text-[10px] rounded bg-surface p-2 overflow-x-auto text-neutral-200",children:Kd(W.responsePayload)})]}):h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No payload snapshot available."})]}),L.errorMessage&&h.jsxs("div",{children:[h.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-neutral-500 mb-2",children:"Error"}),h.jsx("p",{className:"font-mono text-[11px] text-offline",children:L.errorMessage})]})]}):h.jsx("p",{className:"font-mono text-[11px] text-neutral-500",children:"No details available for this row."})}),h.jsx(Nn,{children:h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>M(null),children:"Close"})})]})}),h.jsx($r,{open:O,onOpenChange:ie=>{ie||N(!1)},children:h.jsxs(hr,{children:[h.jsx(pr,{children:h.jsx(mr,{children:"Clear all events"})}),h.jsx("div",{className:"p-4",children:h.jsx("span",{className:"font-mono text-[11px] text-neutral-400",children:"This will permanently delete all request events. Commits are not affected. Are you sure?"})}),h.jsxs(Nn,{children:[h.jsx(Ne,{variant:"default",size:"sm",onClick:()=>N(!1),children:"Cancel"}),h.jsx(Ne,{variant:"destructive",size:"sm",onClick:he,disabled:U.isPending,children:U.isPending?"Clearing...":"Clear all"})]})]})})]})}const VX=co({getParentRoute:()=>uo,path:"/config",component:lX}),GX=co({getParentRoute:()=>uo,path:"/fleet",component:SX}),KX=co({getParentRoute:()=>uo,path:"/",component:cX});function ZX(){const{seq:e}=gk.useParams();return h.jsx(yx,{initialSelectedEntryId:`#${e}`})}const gk=co({getParentRoute:()=>uo,path:"/investigate/commit/$seq",component:ZX});function YX(){const{id:e}=yk.useParams();return h.jsx(yx,{initialSelectedEntryId:`E${e}`})}const yk=co({getParentRoute:()=>uo,path:"/investigate/event/$id",component:YX}),XX=co({getParentRoute:()=>uo,path:"/ops",component:jX}),QX=co({getParentRoute:()=>uo,path:"/storage",component:LX}),WX=co({getParentRoute:()=>uo,path:"/stream",component:yx}),JX=uo.addChildren([KX,WX,gk,yk,GX,XX,QX,VX]),eQ="syncular-console-basepath",tQ="syncular-console-server-url",nQ="syncular-console-token";function rQ(e){if(!e)return;const t=e.trim();return t.length>0?t:void 0}function $v(e){const t=globalThis.document;if(!t)return;const n=t.querySelector(`meta[name="${e}"]`)?.getAttribute("content");return rQ(n)}function vk(e){return!e||e==="/"?"/":(e.startsWith("/")?e:`/${e}`).replace(/\/+$/g,"")||"/"}function sQ(){return vk($v(eQ))}function oQ(){const e=$v(tQ),t=$v(nQ);return!e||!t?null:{serverUrl:e,token:t}}function iQ(){return new k6({defaultOptions:{queries:{staleTime:5e3,retry:1}}})}function aQ(e){return vk(e??sQ())}function cQ(e){const[t]=_.useState(()=>iQ()),n=_.useMemo(()=>DH({routeTree:JX,basepath:aQ(e.basePath)}),[e.basePath]),s=e.defaultConfig===void 0?oQ():e.defaultConfig;return h.jsx(O6,{client:t,children:h.jsx(WH,{defaultConfig:s,children:h.jsx(UH,{router:n})})})}function lQ(e){return h.jsx("div",{className:gx,children:h.jsx(cQ,{...e})})}function uQ(e){const t=document.querySelector(e);if(!t)throw new Error(`Unable to mount console: ${e} not found`);return t}function fQ(e,t={}){const n=uQ(e);HY(n);const s=a6.createRoot(n),i=h.jsx(lQ,{basePath:t.basePath,defaultConfig:t.defaultConfig});return t.strictMode===!1?(s.render(i),s):(s.render(h.jsx(_.StrictMode,{children:i})),s)}var dQ={};const hQ="syncular-sentry-dsn",pQ="syncular-sentry-environment",mQ="syncular-sentry-release";function hu(e){if(!e)return;const t=e.trim();return t.length>0?t:void 0}function By(e){if(typeof document>"u")return;const t=document.querySelector(`meta[name="${e}"]`)?.getAttribute("content");return hu(t)}function Fy(e){if(!(typeof process>"u"))return hu(dQ[e])}function Hy(e){for(const t of e)if(t)return t}function gQ(){const e=Hy([hu(globalThis.__SYNCULAR_SENTRY_DSN__),By(hQ),Fy("SYNCULAR_SENTRY_DSN")]);if(!e)return null;const t=Hy([hu(globalThis.__SYNCULAR_SENTRY_ENVIRONMENT__),By(pQ),Fy("SYNCULAR_SENTRY_ENVIRONMENT")]),n=Hy([hu(globalThis.__SYNCULAR_SENTRY_RELEASE__),By(mQ),Fy("SYNCULAR_SENTRY_RELEASE")]);return{dsn:e,environment:t,release:n,enableLogs:!0,tracesSampleRate:.2,tracePropagationTargets:[/^https?:\/\/.*\/api\/.*/]}}const XC=gQ();XC&&WB(XC);fQ("#root");
@@ -10,7 +10,7 @@
10
10
  <meta name="syncular-sentry-environment" content="" />
11
11
  <meta name="syncular-sentry-release" content="" />
12
12
  <title>@syncular Console</title>
13
- <script type="module" crossorigin src="/assets/index-BS88Pdae.js"></script>
13
+ <script type="module" crossorigin src="/assets/index-cA-JrYOA.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/assets/index-DdqlHztk.css">
15
15
  </head>
16
16
  <body class="syncular-console-root min-h-screen bg-background text-foreground">