UNPKG

straydog-js

Version:

Drop-in API monitoring for any Node.js backend

17 lines (16 loc) 28.6 kB
import{c as Re,j as t,a as V,b as Oe,R as ee,u as O,d as ye,r,e as De,f as je,g as mt,h as Ee,A as ht,P as k,i as j,k as q,l as gt,m as Be,V as vt,n as xt,o as St,p as wt,q as yt,F as Ct,D as bt,C as It,s as Tt,M as Nt}from"./index-2IN6uUS1.js";import{a as Rt}from"./config.axios-CSbZrsaz.js";/** * @license lucide-react v0.338.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Et=Re("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/** * @license lucide-react v0.338.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ve=Re("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/** * @license lucide-react v0.338.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Pt=Re("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);function _e(){let e={loading:!1,error:null,data:null};return{async get(o){e={loading:!0,error:null,data:null};try{return e={loading:!1,error:null,data:(await Rt.get("",{params:o})).data},e}catch(n){return e={loading:!1,error:n?.response?.data?.message||n.message||"Unknown error",data:null},e}},getState:()=>e}}function He({className:e,...o}){return t.jsx("div",{"data-slot":"card",className:V("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",e),...o})}function jt({className:e,...o}){return t.jsx("div",{"data-slot":"card-title",className:V("leading-none font-semibold",e),...o})}function _t({className:e,...o}){return t.jsx("div",{"data-slot":"card-description",className:V("text-muted-foreground text-sm",e),...o})}function Fe({className:e,...o}){return t.jsx("div",{"data-slot":"card-content",className:V("px-6",e),...o})}const Me={ok:"from-green-500/10 via-green-400/5 to-green-500/10",error:"from-red-500/10 via-red-400/5 to-red-500/10",warning:"from-yellow-500/10 via-yellow-400/5 to-yellow-500/10"},Ae={ok:"from-green-400 via-green-300 to-green-400",error:"from-red-400 via-red-300 to-red-400",warning:"from-yellow-400 via-yellow-300 to-yellow-400"},ke={ok:"from-gray-900 via-green-950 to-gray-900",error:"from-gray-900 via-red-950 to-gray-900",warning:"from-gray-900 via-yellow-950 to-gray-900"},Mt=({title:e,value:o,description:n,unit:l,type:i})=>{const f=Me[i]||Me.ok,s=Ae[i]||Ae.ok,a=ke[i]||ke.ok;return t.jsxs(He,{className:`relative w-[300px] overflow-hidden rounded-2xl border border-gray-200/20 bg-gradient-to-br ${a} shadow-lg transition-transform hover:scale-[1.02] hover:shadow-2xl`,children:[t.jsx("div",{className:`absolute inset-0 bg-gradient-to-tr ${f} opacity-60 pointer-events-none`}),t.jsxs(Fe,{className:"px-4 pt-0 relative z-10",children:[t.jsx(jt,{className:"text-lg font-semibold tracking-tight text-white",children:e}),t.jsx(_t,{className:"text-sm text-gray-300",children:n}),t.jsxs("div",{className:"flex items-baseline gap-1",children:[t.jsx("span",{className:`text-xl font-bold bg-gradient-to-r ${s} bg-clip-text text-transparent`,children:o||0}),t.jsx("span",{className:"text-sm font-medium text-gray-400",children:l})]})]})]})},de={averageLatency:{title:"Average Latency",description:"",type:"ok",unit:"ms"},count:{title:"Total Requests",description:"",type:"ok",unit:""},failedCount:{title:"Total Failed Requests",unit:"",type:"error",description:""},failureRate:{title:"Failure Rate",unit:"%",type:"error",description:""},fastestEndpoint:{title:"Fastest Endpoint",unit:"",type:"ok",description:"endpoint"},mostFailedEndpoint:{title:"Most Failed Endpoint",unit:"",type:"error",description:""},mostSuccessfulEndpoint:{title:"Most Success Endpoint",unit:"",type:"ok",description:""},slowestEndpoint:{title:"Slowest Endpoint",unit:"",type:"warning",description:""},successCount:{title:"Total Success Requests",unit:"",type:"ok",description:""},successRate:{title:"Success Rate",unit:"%",type:"ok",description:""},highestTraffic:{title:"Highest Traffic",unit:"",type:"ok",description:"endpoint"}};function Le(e,[o,n]){return Math.min(n,Math.max(o,e))}function At(e){const o=e+"CollectionProvider",[n,l]=Oe(o),[i,f]=n(o,{collectionRef:{current:null},itemMap:new Map}),s=c=>{const{scope:u,children:S}=c,m=ee.useRef(null),p=ee.useRef(new Map).current;return t.jsx(i,{scope:u,itemMap:p,collectionRef:m,children:S})};s.displayName=o;const a=e+"CollectionSlot",d=ye(a),h=ee.forwardRef((c,u)=>{const{scope:S,children:m}=c,p=f(a,S),N=O(u,p.collectionRef);return t.jsx(d,{ref:N,children:m})});h.displayName=a;const x=e+"CollectionItemSlot",w="data-radix-collection-item",I=ye(x),y=ee.forwardRef((c,u)=>{const{scope:S,children:m,...p}=c,N=ee.useRef(null),R=O(u,N),_=f(x,S);return ee.useEffect(()=>(_.itemMap.set(N,{ref:N,...p}),()=>void _.itemMap.delete(N))),t.jsx(I,{[w]:"",ref:R,children:m})});y.displayName=x;function v(c){const u=f(e+"CollectionConsumer",c);return ee.useCallback(()=>{const m=u.collectionRef.current;if(!m)return[];const p=Array.from(m.querySelectorAll(`[${w}]`));return Array.from(u.itemMap.values()).sort((_,E)=>p.indexOf(_.ref.current)-p.indexOf(E.ref.current))},[u.collectionRef,u.itemMap])}return[{Provider:s,Slot:h,ItemSlot:y},v,l]}var kt=r.createContext(void 0);function Lt(e){const o=r.useContext(kt);return e||o||"ltr"}function Ot(e){const o=r.useRef({value:e,previous:e});return r.useMemo(()=>(o.current.value!==e&&(o.current.previous=o.current.value,o.current.value=e),o.current.previous),[e])}var Dt=[" ","Enter","ArrowUp","ArrowDown"],Bt=[" ","Enter"],te="Select",[pe,fe,Vt]=At(te),[re,Eo]=Oe(te,[Vt,De]),me=De(),[Ht,Y]=re(te),[Ft,Ut]=re(te),Ue=e=>{const{__scopeSelect:o,children:n,open:l,defaultOpen:i,onOpenChange:f,value:s,defaultValue:a,onValueChange:d,dir:h,name:x,autoComplete:w,disabled:I,required:y,form:v}=e,c=me(o),[u,S]=r.useState(null),[m,p]=r.useState(null),[N,R]=r.useState(!1),_=Lt(h),[E,L]=je({prop:l,defaultProp:i??!1,onChange:f,caller:te}),[K,Z]=je({prop:s,defaultProp:a,onChange:d,caller:te}),H=r.useRef(null),F=u?v||!!u.closest("form"):!0,[G,U]=r.useState(new Set),z=Array.from(G).map(M=>M.props.value).join(";");return t.jsx(mt,{...c,children:t.jsxs(Ht,{required:y,scope:o,trigger:u,onTriggerChange:S,valueNode:m,onValueNodeChange:p,valueNodeHasChildren:N,onValueNodeHasChildrenChange:R,contentId:Ee(),value:K,onValueChange:Z,open:E,onOpenChange:L,dir:_,triggerPointerDownPosRef:H,disabled:I,children:[t.jsx(pe.Provider,{scope:o,children:t.jsx(Ft,{scope:e.__scopeSelect,onNativeOptionAdd:r.useCallback(M=>{U(B=>new Set(B).add(M))},[]),onNativeOptionRemove:r.useCallback(M=>{U(B=>{const W=new Set(B);return W.delete(M),W})},[]),children:n})}),F?t.jsxs(dt,{"aria-hidden":!0,required:y,tabIndex:-1,name:x,autoComplete:w,value:K,onChange:M=>Z(M.target.value),disabled:I,form:v,children:[K===void 0?t.jsx("option",{value:""}):null,Array.from(G)]},z):null]})})};Ue.displayName=te;var ze="SelectTrigger",We=r.forwardRef((e,o)=>{const{__scopeSelect:n,disabled:l=!1,...i}=e,f=me(n),s=Y(ze,n),a=s.disabled||l,d=O(o,s.onTriggerChange),h=fe(n),x=r.useRef("touch"),[w,I,y]=pt(c=>{const u=h().filter(p=>!p.disabled),S=u.find(p=>p.value===s.value),m=ft(u,c,S);m!==void 0&&s.onValueChange(m.value)}),v=c=>{a||(s.onOpenChange(!0),y()),c&&(s.triggerPointerDownPosRef.current={x:Math.round(c.pageX),y:Math.round(c.pageY)})};return t.jsx(ht,{asChild:!0,...f,children:t.jsx(k.button,{type:"button",role:"combobox","aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":"none",dir:s.dir,"data-state":s.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":ut(s.value)?"":void 0,...i,ref:d,onClick:j(i.onClick,c=>{c.currentTarget.focus(),x.current!=="mouse"&&v(c)}),onPointerDown:j(i.onPointerDown,c=>{x.current=c.pointerType;const u=c.target;u.hasPointerCapture(c.pointerId)&&u.releasePointerCapture(c.pointerId),c.button===0&&c.ctrlKey===!1&&c.pointerType==="mouse"&&(v(c),c.preventDefault())}),onKeyDown:j(i.onKeyDown,c=>{const u=w.current!=="";!(c.ctrlKey||c.altKey||c.metaKey)&&c.key.length===1&&I(c.key),!(u&&c.key===" ")&&Dt.includes(c.key)&&(v(),c.preventDefault())})})})});We.displayName=ze;var Ke="SelectValue",Ge=r.forwardRef((e,o)=>{const{__scopeSelect:n,className:l,style:i,children:f,placeholder:s="",...a}=e,d=Y(Ke,n),{onValueNodeHasChildrenChange:h}=d,x=f!==void 0,w=O(o,d.onValueNodeChange);return q(()=>{h(x)},[h,x]),t.jsx(k.span,{...a,ref:w,style:{pointerEvents:"none"},children:ut(d.value)?t.jsx(t.Fragment,{children:s}):f})});Ge.displayName=Ke;var zt="SelectIcon",$e=r.forwardRef((e,o)=>{const{__scopeSelect:n,children:l,...i}=e;return t.jsx(k.span,{"aria-hidden":!0,...i,ref:o,children:l||"▼"})});$e.displayName=zt;var Wt="SelectPortal",qe=e=>t.jsx(gt,{asChild:!0,...e});qe.displayName=Wt;var oe="SelectContent",Ye=r.forwardRef((e,o)=>{const n=Y(oe,e.__scopeSelect),[l,i]=r.useState();if(q(()=>{i(new DocumentFragment)},[]),!n.open){const f=l;return f?Be.createPortal(t.jsx(Xe,{scope:e.__scopeSelect,children:t.jsx(pe.Slot,{scope:e.__scopeSelect,children:t.jsx("div",{children:e.children})})}),f):null}return t.jsx(Ze,{...e,ref:o})});Ye.displayName=oe;var D=10,[Xe,X]=re(oe),Kt="SelectContentImpl",Gt=ye("SelectContent.RemoveScroll"),Ze=r.forwardRef((e,o)=>{const{__scopeSelect:n,position:l="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:f,onPointerDownOutside:s,side:a,sideOffset:d,align:h,alignOffset:x,arrowPadding:w,collisionBoundary:I,collisionPadding:y,sticky:v,hideWhenDetached:c,avoidCollisions:u,...S}=e,m=Y(oe,n),[p,N]=r.useState(null),[R,_]=r.useState(null),E=O(o,g=>N(g)),[L,K]=r.useState(null),[Z,H]=r.useState(null),F=fe(n),[G,U]=r.useState(!1),z=r.useRef(!1);r.useEffect(()=>{if(p)return St(p)},[p]),wt();const M=r.useCallback(g=>{const[T,...A]=F().map(P=>P.ref.current),[C]=A.slice(-1),b=document.activeElement;for(const P of g)if(P===b||(P?.scrollIntoView({block:"nearest"}),P===T&&R&&(R.scrollTop=0),P===C&&R&&(R.scrollTop=R.scrollHeight),P?.focus(),document.activeElement!==b))return},[F,R]),B=r.useCallback(()=>M([L,p]),[M,L,p]);r.useEffect(()=>{G&&B()},[G,B]);const{onOpenChange:W,triggerPointerDownPosRef:$}=m;r.useEffect(()=>{if(p){let g={x:0,y:0};const T=C=>{g={x:Math.abs(Math.round(C.pageX)-($.current?.x??0)),y:Math.abs(Math.round(C.pageY)-($.current?.y??0))}},A=C=>{g.x<=10&&g.y<=10?C.preventDefault():p.contains(C.target)||W(!1),document.removeEventListener("pointermove",T),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",T),document.addEventListener("pointerup",A,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",A,{capture:!0})}}},[p,W,$]),r.useEffect(()=>{const g=()=>W(!1);return window.addEventListener("blur",g),window.addEventListener("resize",g),()=>{window.removeEventListener("blur",g),window.removeEventListener("resize",g)}},[W]);const[he,ie]=pt(g=>{const T=F().filter(b=>!b.disabled),A=T.find(b=>b.ref.current===document.activeElement),C=ft(T,g,A);C&&setTimeout(()=>C.ref.current.focus())}),ge=r.useCallback((g,T,A)=>{const C=!z.current&&!A;(m.value!==void 0&&m.value===T||C)&&(K(g),C&&(z.current=!0))},[m.value]),ve=r.useCallback(()=>p?.focus(),[p]),ne=r.useCallback((g,T,A)=>{const C=!z.current&&!A;(m.value!==void 0&&m.value===T||C)&&H(g)},[m.value]),ce=l==="popper"?Ce:Je,se=ce===Ce?{side:a,sideOffset:d,align:h,alignOffset:x,arrowPadding:w,collisionBoundary:I,collisionPadding:y,sticky:v,hideWhenDetached:c,avoidCollisions:u}:{};return t.jsx(Xe,{scope:n,content:p,viewport:R,onViewportChange:_,itemRefCallback:ge,selectedItem:L,onItemLeave:ve,itemTextRefCallback:ne,focusSelectedItem:B,selectedItemText:Z,position:l,isPositioned:G,searchRef:he,children:t.jsx(yt,{as:Gt,allowPinchZoom:!0,children:t.jsx(Ct,{asChild:!0,trapped:m.open,onMountAutoFocus:g=>{g.preventDefault()},onUnmountAutoFocus:j(i,g=>{m.trigger?.focus({preventScroll:!0}),g.preventDefault()}),children:t.jsx(bt,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:f,onPointerDownOutside:s,onFocusOutside:g=>g.preventDefault(),onDismiss:()=>m.onOpenChange(!1),children:t.jsx(ce,{role:"listbox",id:m.contentId,"data-state":m.open?"open":"closed",dir:m.dir,onContextMenu:g=>g.preventDefault(),...S,...se,onPlaced:()=>U(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...S.style},onKeyDown:j(S.onKeyDown,g=>{const T=g.ctrlKey||g.altKey||g.metaKey;if(g.key==="Tab"&&g.preventDefault(),!T&&g.key.length===1&&ie(g.key),["ArrowUp","ArrowDown","Home","End"].includes(g.key)){let C=F().filter(b=>!b.disabled).map(b=>b.ref.current);if(["ArrowUp","End"].includes(g.key)&&(C=C.slice().reverse()),["ArrowUp","ArrowDown"].includes(g.key)){const b=g.target,P=C.indexOf(b);C=C.slice(P+1)}setTimeout(()=>M(C)),g.preventDefault()}})})})})})})});Ze.displayName=Kt;var $t="SelectItemAlignedPosition",Je=r.forwardRef((e,o)=>{const{__scopeSelect:n,onPlaced:l,...i}=e,f=Y(oe,n),s=X(oe,n),[a,d]=r.useState(null),[h,x]=r.useState(null),w=O(o,E=>x(E)),I=fe(n),y=r.useRef(!1),v=r.useRef(!0),{viewport:c,selectedItem:u,selectedItemText:S,focusSelectedItem:m}=s,p=r.useCallback(()=>{if(f.trigger&&f.valueNode&&a&&h&&c&&u&&S){const E=f.trigger.getBoundingClientRect(),L=h.getBoundingClientRect(),K=f.valueNode.getBoundingClientRect(),Z=S.getBoundingClientRect();if(f.dir!=="rtl"){const b=Z.left-L.left,P=K.left-b,J=E.left-P,Q=E.width+J,xe=Math.max(Q,L.width),Se=window.innerWidth-D,we=Le(P,[D,Math.max(D,Se-xe)]);a.style.minWidth=Q+"px",a.style.left=we+"px"}else{const b=L.right-Z.right,P=window.innerWidth-K.right-b,J=window.innerWidth-E.right-P,Q=E.width+J,xe=Math.max(Q,L.width),Se=window.innerWidth-D,we=Le(P,[D,Math.max(D,Se-xe)]);a.style.minWidth=Q+"px",a.style.right=we+"px"}const H=I(),F=window.innerHeight-D*2,G=c.scrollHeight,U=window.getComputedStyle(h),z=parseInt(U.borderTopWidth,10),M=parseInt(U.paddingTop,10),B=parseInt(U.borderBottomWidth,10),W=parseInt(U.paddingBottom,10),$=z+M+G+W+B,he=Math.min(u.offsetHeight*5,$),ie=window.getComputedStyle(c),ge=parseInt(ie.paddingTop,10),ve=parseInt(ie.paddingBottom,10),ne=E.top+E.height/2-D,ce=F-ne,se=u.offsetHeight/2,g=u.offsetTop+se,T=z+M+g,A=$-T;if(T<=ne){const b=H.length>0&&u===H[H.length-1].ref.current;a.style.bottom="0px";const P=h.clientHeight-c.offsetTop-c.offsetHeight,J=Math.max(ce,se+(b?ve:0)+P+B),Q=T+J;a.style.height=Q+"px"}else{const b=H.length>0&&u===H[0].ref.current;a.style.top="0px";const J=Math.max(ne,z+c.offsetTop+(b?ge:0)+se)+A;a.style.height=J+"px",c.scrollTop=T-ne+c.offsetTop}a.style.margin=`${D}px 0`,a.style.minHeight=he+"px",a.style.maxHeight=F+"px",l?.(),requestAnimationFrame(()=>y.current=!0)}},[I,f.trigger,f.valueNode,a,h,c,u,S,f.dir,l]);q(()=>p(),[p]);const[N,R]=r.useState();q(()=>{h&&R(window.getComputedStyle(h).zIndex)},[h]);const _=r.useCallback(E=>{E&&v.current===!0&&(p(),m?.(),v.current=!1)},[p,m]);return t.jsx(Yt,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:y,onScrollButtonChange:_,children:t.jsx("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:t.jsx(k.div,{...i,ref:w,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});Je.displayName=$t;var qt="SelectPopperPosition",Ce=r.forwardRef((e,o)=>{const{__scopeSelect:n,align:l="start",collisionPadding:i=D,...f}=e,s=me(n);return t.jsx(It,{...s,...f,ref:o,align:l,collisionPadding:i,style:{boxSizing:"border-box",...f.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Ce.displayName=qt;var[Yt,Pe]=re(oe,{}),be="SelectViewport",Qe=r.forwardRef((e,o)=>{const{__scopeSelect:n,nonce:l,...i}=e,f=X(be,n),s=Pe(be,n),a=O(o,f.onViewportChange),d=r.useRef(0);return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:l}),t.jsx(pe.Slot,{scope:n,children:t.jsx(k.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:j(i.onScroll,h=>{const x=h.currentTarget,{contentWrapper:w,shouldExpandOnScrollRef:I}=s;if(I?.current&&w){const y=Math.abs(d.current-x.scrollTop);if(y>0){const v=window.innerHeight-D*2,c=parseFloat(w.style.minHeight),u=parseFloat(w.style.height),S=Math.max(c,u);if(S<v){const m=S+y,p=Math.min(v,m),N=m-p;w.style.height=p+"px",w.style.bottom==="0px"&&(x.scrollTop=N>0?N:0,w.style.justifyContent="flex-end")}}}d.current=x.scrollTop})})})]})});Qe.displayName=be;var et="SelectGroup",[Xt,Zt]=re(et),Jt=r.forwardRef((e,o)=>{const{__scopeSelect:n,...l}=e,i=Ee();return t.jsx(Xt,{scope:n,id:i,children:t.jsx(k.div,{role:"group","aria-labelledby":i,...l,ref:o})})});Jt.displayName=et;var tt="SelectLabel",Qt=r.forwardRef((e,o)=>{const{__scopeSelect:n,...l}=e,i=Zt(tt,n);return t.jsx(k.div,{id:i.id,...l,ref:o})});Qt.displayName=tt;var ue="SelectItem",[eo,ot]=re(ue),nt=r.forwardRef((e,o)=>{const{__scopeSelect:n,value:l,disabled:i=!1,textValue:f,...s}=e,a=Y(ue,n),d=X(ue,n),h=a.value===l,[x,w]=r.useState(f??""),[I,y]=r.useState(!1),v=O(o,m=>d.itemRefCallback?.(m,l,i)),c=Ee(),u=r.useRef("touch"),S=()=>{i||(a.onValueChange(l),a.onOpenChange(!1))};if(l==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return t.jsx(eo,{scope:n,value:l,disabled:i,textId:c,isSelected:h,onItemTextChange:r.useCallback(m=>{w(p=>p||(m?.textContent??"").trim())},[]),children:t.jsx(pe.ItemSlot,{scope:n,value:l,disabled:i,textValue:x,children:t.jsx(k.div,{role:"option","aria-labelledby":c,"data-highlighted":I?"":void 0,"aria-selected":h&&I,"data-state":h?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...s,ref:v,onFocus:j(s.onFocus,()=>y(!0)),onBlur:j(s.onBlur,()=>y(!1)),onClick:j(s.onClick,()=>{u.current!=="mouse"&&S()}),onPointerUp:j(s.onPointerUp,()=>{u.current==="mouse"&&S()}),onPointerDown:j(s.onPointerDown,m=>{u.current=m.pointerType}),onPointerMove:j(s.onPointerMove,m=>{u.current=m.pointerType,i?d.onItemLeave?.():u.current==="mouse"&&m.currentTarget.focus({preventScroll:!0})}),onPointerLeave:j(s.onPointerLeave,m=>{m.currentTarget===document.activeElement&&d.onItemLeave?.()}),onKeyDown:j(s.onKeyDown,m=>{d.searchRef?.current!==""&&m.key===" "||(Bt.includes(m.key)&&S(),m.key===" "&&m.preventDefault())})})})})});nt.displayName=ue;var le="SelectItemText",rt=r.forwardRef((e,o)=>{const{__scopeSelect:n,className:l,style:i,...f}=e,s=Y(le,n),a=X(le,n),d=ot(le,n),h=Ut(le,n),[x,w]=r.useState(null),I=O(o,S=>w(S),d.onItemTextChange,S=>a.itemTextRefCallback?.(S,d.value,d.disabled)),y=x?.textContent,v=r.useMemo(()=>t.jsx("option",{value:d.value,disabled:d.disabled,children:y},d.value),[d.disabled,d.value,y]),{onNativeOptionAdd:c,onNativeOptionRemove:u}=h;return q(()=>(c(v),()=>u(v)),[c,u,v]),t.jsxs(t.Fragment,{children:[t.jsx(k.span,{id:d.textId,...f,ref:I}),d.isSelected&&s.valueNode&&!s.valueNodeHasChildren?Be.createPortal(f.children,s.valueNode):null]})});rt.displayName=le;var st="SelectItemIndicator",at=r.forwardRef((e,o)=>{const{__scopeSelect:n,...l}=e;return ot(st,n).isSelected?t.jsx(k.span,{"aria-hidden":!0,...l,ref:o}):null});at.displayName=st;var Ie="SelectScrollUpButton",lt=r.forwardRef((e,o)=>{const n=X(Ie,e.__scopeSelect),l=Pe(Ie,e.__scopeSelect),[i,f]=r.useState(!1),s=O(o,l.onScrollButtonChange);return q(()=>{if(n.viewport&&n.isPositioned){let a=function(){const h=d.scrollTop>0;f(h)};const d=n.viewport;return a(),d.addEventListener("scroll",a),()=>d.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),i?t.jsx(ct,{...e,ref:s,onAutoScroll:()=>{const{viewport:a,selectedItem:d}=n;a&&d&&(a.scrollTop=a.scrollTop-d.offsetHeight)}}):null});lt.displayName=Ie;var Te="SelectScrollDownButton",it=r.forwardRef((e,o)=>{const n=X(Te,e.__scopeSelect),l=Pe(Te,e.__scopeSelect),[i,f]=r.useState(!1),s=O(o,l.onScrollButtonChange);return q(()=>{if(n.viewport&&n.isPositioned){let a=function(){const h=d.scrollHeight-d.clientHeight,x=Math.ceil(d.scrollTop)<h;f(x)};const d=n.viewport;return a(),d.addEventListener("scroll",a),()=>d.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),i?t.jsx(ct,{...e,ref:s,onAutoScroll:()=>{const{viewport:a,selectedItem:d}=n;a&&d&&(a.scrollTop=a.scrollTop+d.offsetHeight)}}):null});it.displayName=Te;var ct=r.forwardRef((e,o)=>{const{__scopeSelect:n,onAutoScroll:l,...i}=e,f=X("SelectScrollButton",n),s=r.useRef(null),a=fe(n),d=r.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return r.useEffect(()=>()=>d(),[d]),q(()=>{a().find(x=>x.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[a]),t.jsx(k.div,{"aria-hidden":!0,...i,ref:o,style:{flexShrink:0,...i.style},onPointerDown:j(i.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(l,50))}),onPointerMove:j(i.onPointerMove,()=>{f.onItemLeave?.(),s.current===null&&(s.current=window.setInterval(l,50))}),onPointerLeave:j(i.onPointerLeave,()=>{d()})})}),to="SelectSeparator",oo=r.forwardRef((e,o)=>{const{__scopeSelect:n,...l}=e;return t.jsx(k.div,{"aria-hidden":!0,...l,ref:o})});oo.displayName=to;var Ne="SelectArrow",no=r.forwardRef((e,o)=>{const{__scopeSelect:n,...l}=e,i=me(n),f=Y(Ne,n),s=X(Ne,n);return f.open&&s.position==="popper"?t.jsx(Tt,{...i,...l,ref:o}):null});no.displayName=Ne;var ro="SelectBubbleInput",dt=r.forwardRef(({__scopeSelect:e,value:o,...n},l)=>{const i=r.useRef(null),f=O(l,i),s=Ot(o);return r.useEffect(()=>{const a=i.current;if(!a)return;const d=window.HTMLSelectElement.prototype,x=Object.getOwnPropertyDescriptor(d,"value").set;if(s!==o&&x){const w=new Event("change",{bubbles:!0});x.call(a,o),a.dispatchEvent(w)}},[s,o]),t.jsx(k.select,{...n,style:{...vt,...n.style},ref:f,defaultValue:o})});dt.displayName=ro;function ut(e){return e===""||e===void 0}function pt(e){const o=xt(e),n=r.useRef(""),l=r.useRef(0),i=r.useCallback(s=>{const a=n.current+s;o(a),(function d(h){n.current=h,window.clearTimeout(l.current),h!==""&&(l.current=window.setTimeout(()=>d(""),1e3))})(a)},[o]),f=r.useCallback(()=>{n.current="",window.clearTimeout(l.current)},[]);return r.useEffect(()=>()=>window.clearTimeout(l.current),[]),[n,i,f]}function ft(e,o,n){const i=o.length>1&&Array.from(o).every(h=>h===o[0])?o[0]:o,f=n?e.indexOf(n):-1;let s=so(e,Math.max(f,0));i.length===1&&(s=s.filter(h=>h!==n));const d=s.find(h=>h.textValue.toLowerCase().startsWith(i.toLowerCase()));return d!==n?d:void 0}function so(e,o){return e.map((n,l)=>e[(o+l)%e.length])}var ao=Ue,lo=We,io=Ge,co=$e,uo=qe,po=Ye,fo=Qe,mo=nt,ho=rt,go=at,vo=lt,xo=it;function So({...e}){return t.jsx(ao,{"data-slot":"select",...e})}function wo({...e}){return t.jsx(io,{"data-slot":"select-value",...e})}function yo({className:e,size:o="default",children:n,...l}){return t.jsxs(lo,{"data-slot":"select-trigger","data-size":o,className:V("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...l,children:[n,t.jsx(co,{asChild:!0,children:t.jsx(Ve,{className:"size-4 opacity-50"})})]})}function Co({className:e,children:o,position:n="popper",...l}){return t.jsx(uo,{children:t.jsxs(po,{"data-slot":"select-content",className:V("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...l,children:[t.jsx(bo,{}),t.jsx(fo,{className:V("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:o}),t.jsx(Io,{})]})})}function ae({className:e,children:o,...n}){return t.jsxs(mo,{"data-slot":"select-item",className:V("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[t.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:t.jsx(go,{children:t.jsx(Et,{className:"size-4"})})}),t.jsx(ho,{children:o})]})}function bo({className:e,...o}){return t.jsx(vo,{"data-slot":"select-scroll-up-button",className:V("flex cursor-default items-center justify-center py-1",e),...o,children:t.jsx(Pt,{className:"size-4"})})}function Io({className:e,...o}){return t.jsx(xo,{"data-slot":"select-scroll-down-button",className:V("flex cursor-default items-center justify-center py-1",e),...o,children:t.jsx(Ve,{className:"size-4"})})}const To=({endpoints:e})=>t.jsx(t.Fragment,{children:e.map(o=>t.jsx(He,{className:"py-0 mb-1 w-1/3 border-0 border-b-1 shadow-none rounded-none",children:t.jsxs(Fe,{className:"py-1 px-2 flex justify-between pe-6",children:[t.jsx("a",{className:"text-blue-500",children:o.path}),t.jsx("span",{className:"font-medium",children:o.methods[0]})]})}))});function Po(){const e=new URLSearchParams(window.location.search),[o,n]=r.useState([]),[l,i]=r.useState(e.get("days")||"1"),[f,s]=r.useState(!1),[a,d]=r.useState(null),[h,x]=r.useState([]),w=_e(),I=_e();async function y(){s(c=>!c);const v=[];try{const c=[w.get({method:"getStats",days:l}),I.get({method:"getEndpoints"})],[{data:u},{data:S}]=await Promise.all(c);for(const m in u)if(m in de){const p=m,N=de[p].title;let R="",_=u[p]||"";const E=de[p].unit,L=de[p].type;(p==="fastestEndpoint"||p==="slowestEndpoint")&&typeof u[p]=="object"&&u[p]!==null&&(R=`Average latency is ${u[p].averageLatency} ms`,_=u[p].endpoint),p=="highestTraffic"&&typeof u[p]=="object"&&u[p]!==null&&(R=`Number of requests is ${u[p].count}`,_=u[p].endpoint),v.push({title:N,description:R,value:_,unit:E,type:L})}n(v),s(!1),x(S)}catch{d("Error connecting to server!"),s(!1)}}return r.useEffect(()=>{const v=new URL(window.location.href);v.searchParams.set("days",l),window.history.replaceState({},"",v),y()},[l]),a?t.jsx("div",{children:t.jsx("h3",{children:a})}):f?t.jsx(Nt,{}):t.jsxs("div",{children:[t.jsx("div",{className:"mb-6",children:t.jsxs(So,{defaultValue:l,onValueChange:v=>i(v),children:[t.jsx(yo,{className:"w-[180px]",children:t.jsx(wo,{placeholder:"Time Range"})}),t.jsxs(Co,{children:[t.jsx(ae,{value:"1",children:"Last day"}),t.jsx(ae,{value:"3",children:"Last 3 days"}),t.jsx(ae,{value:"7",children:"Last week"}),t.jsx(ae,{value:"30",children:"Last month"}),t.jsx(ae,{value:"90",children:"Last 3 months"})]})]})}),t.jsx("div",{className:"grid grid-cols-4 gap-3",children:o.map(v=>t.jsx(Mt,{title:v.title,description:v.description,value:v.value,type:v.type,unit:v.unit},v.value))}),t.jsxs("div",{className:"py-4",children:[t.jsx("h2",{className:"text-2xl font-semibold mt-3 mb-4",children:"Endpoint List"}),t.jsx(To,{endpoints:h})]})]})}export{Po as default};