mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 21:00:06 +01:00
2 lines
155 KiB
JavaScript
2 lines
155 KiB
JavaScript
import{t as ia,m as oa,r as o,j as e,n as qs,z as yt,F as la,C as da,p as ca,q as ma,v as re,w as F,_ as Je,x as js,y as St,A as te,B as ae,D as ee,E as Oe,G as us,T as xa,J as ha,H as ua}from"./vendor-DvippHRz.js";import{S as Cs,R as ja,a as Ct,C as _t,b as kt,T as At,D as Et,P as $t,O as Lt,c as fa,d as pa,e as ga,f as va,g as ba,A as Na,h as wa,i as ya,j as Sa,k as Ca,l as _a,m as ka,n as Aa,I as Ea,o as $a,p as La,q as Da,r as Ia,s as Ta,t as Pa,u as Ma,v as Oa,w as za,x as Fa,y as Ra,z as Va,B as Ua,E as Ba,V as Ha,F as Ka,G as qa,H as Ga,J as Ja,K as Qa,L as Wa,M as Ya,N as Xa,Q as Za,U as en}from"./radix-DRmH1vcw.js";import{X as Dt,S as sn,M as tn,L as an,C as bs,H as nn,A as rn,B as on,a as ln,T as It,b as dn,c as hs,d as cn,K as mn,F as xn,e as hn,f as un,G as jn,g as fn,U as mt,h as pn,i as gn,j as vn,k as Gs,l as bn,m as Nn,P as Qe,n as rs,o as Ue,p as Ts,R as Ps,q as ye,r as qe,s as wn,t as $s,u as yn,v as Sn,w as Cn,x as _n,y as xt}from"./icons-B5E6SSBo.js";import{u as Ms,L as as,O as Js,N as Qs,a as _s,b as Tt,R as kn,c as se,B as An}from"./router-CANfZtzM.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))d(u);new MutationObserver(u=>{for(const f of u)if(f.type==="childList")for(const $ of f.addedNodes)$.tagName==="LINK"&&$.rel==="modulepreload"&&d($)}).observe(document,{childList:!0,subtree:!0});function r(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function d(u){if(u.ep)return;u.ep=!0;const f=r(u);fetch(u.href,f)}})();function L(...s){return ia(oa(s))}function ht(s){return s.toLowerCase().trim().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)+/g,"")}const Us=768;function En(){const[s,t]=o.useState(void 0);return o.useEffect(()=>{const r=window.matchMedia(`(max-width: ${Us-1}px)`),d=()=>{t(window.innerWidth<Us)};return r.addEventListener("change",d),t(window.innerWidth<Us),()=>r.removeEventListener("change",d)},[]),!!s}const Ws=qs("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function h({className:s,variant:t,size:r,asChild:d=!1,...u}){const f=d?Cs:"button";return e.jsx(f,{"data-slot":"button",className:L(Ws({variant:t,size:r,className:s})),...u})}function z({className:s,type:t,...r}){return e.jsx("input",{type:t,"data-slot":"input",className:L("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",s),...r})}function Ns({className:s,orientation:t="horizontal",decorative:r=!0,...d}){return e.jsx(ja,{"data-slot":"separator",decorative:r,orientation:t,className:L("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",s),...d})}function $n({...s}){return e.jsx(Ct,{"data-slot":"sheet",...s})}function Ln({...s}){return e.jsx($t,{"data-slot":"sheet-portal",...s})}function Dn({className:s,...t}){return e.jsx(Lt,{"data-slot":"sheet-overlay",className:L("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",s),...t})}function In({className:s,children:t,side:r="right",...d}){return e.jsxs(Ln,{children:[e.jsx(Dn,{}),e.jsxs(_t,{"data-slot":"sheet-content",className:L("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",r==="right"&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",r==="left"&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",r==="top"&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",r==="bottom"&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",s),...d,children:[t,e.jsxs(kt,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none",children:[e.jsx(Dt,{className:"size-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Tn({className:s,...t}){return e.jsx("div",{"data-slot":"sheet-header",className:L("flex flex-col gap-1.5 p-4",s),...t})}function Pn({className:s,...t}){return e.jsx(At,{"data-slot":"sheet-title",className:L("text-foreground font-semibold",s),...t})}function Mn({className:s,...t}){return e.jsx(Et,{"data-slot":"sheet-description",className:L("text-muted-foreground text-sm",s),...t})}function Ge({className:s,...t}){return e.jsx("div",{"data-slot":"skeleton",className:L("bg-accent animate-pulse rounded-md",s),...t})}function Os({delayDuration:s=0,...t}){return e.jsx(fa,{"data-slot":"tooltip-provider",delayDuration:s,...t})}function Ys({...s}){return e.jsx(Os,{children:e.jsx(pa,{"data-slot":"tooltip",...s})})}function Xs({...s}){return e.jsx(ga,{"data-slot":"tooltip-trigger",...s})}function Zs({className:s,sideOffset:t=0,children:r,...d}){return e.jsx(va,{children:e.jsxs(ba,{"data-slot":"tooltip-content",sideOffset:t,className:L("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",s),...d,children:[r,e.jsx(Na,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}const On="sidebar_state",zn=3600*24*7,Fn="16rem",Rn="18rem",Vn="3rem",Un="b",Pt=o.createContext(null);function Mt(){const s=o.useContext(Pt);if(!s)throw new Error("useSidebar must be used within a SidebarProvider.");return s}function Bn({defaultOpen:s=!0,open:t,onOpenChange:r,className:d,style:u,children:f,...$}){const C=En(),[O,M]=o.useState(!1),[R,U]=o.useState(s),T=t??R,P=o.useCallback(m=>{const x=typeof m=="function"?m(T):m;r?r(x):U(x),document.cookie=`${On}=${x}; path=/; max-age=${zn}`},[r,T]),j=o.useCallback(()=>C?M(m=>!m):P(m=>!m),[C,P,M]);o.useEffect(()=>{const m=x=>{x.key===Un&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),j())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[j]);const V=T?"expanded":"collapsed",H=o.useMemo(()=>({state:V,open:T,setOpen:P,isMobile:C,openMobile:O,setOpenMobile:M,toggleSidebar:j}),[V,T,P,C,O,M,j]);return e.jsx(Pt.Provider,{value:H,children:e.jsx(Os,{delayDuration:0,children:e.jsx("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":Fn,"--sidebar-width-icon":Vn,...u},className:L("group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",d),...$,children:f})})})}function Hn({side:s="left",variant:t="sidebar",collapsible:r="offcanvas",className:d,children:u,...f}){const{isMobile:$,state:C,openMobile:O,setOpenMobile:M}=Mt();return r==="none"?e.jsx("div",{"data-slot":"sidebar",className:L("bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",d),...f,children:u}):$?e.jsx($n,{open:O,onOpenChange:M,...f,children:e.jsxs(In,{"data-sidebar":"sidebar","data-slot":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden",style:{"--sidebar-width":Rn},side:s,children:[e.jsxs(Tn,{className:"sr-only",children:[e.jsx(Pn,{children:"Sidebar"}),e.jsx(Mn,{children:"Displays the mobile sidebar."})]}),e.jsx("div",{className:"flex h-full w-full flex-col",children:u})]})}):e.jsxs("div",{className:"group peer text-sidebar-foreground hidden md:block","data-state":C,"data-collapsible":C==="collapsed"?r:"","data-variant":t,"data-side":s,"data-slot":"sidebar",children:[e.jsx("div",{"data-slot":"sidebar-gap",className:L("relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),e.jsx("div",{"data-slot":"sidebar-container",className:L("fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",s==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",d),...f,children:e.jsx("div",{"data-sidebar":"sidebar","data-slot":"sidebar-inner",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm",children:u})})]})}function Kn({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:L("flex flex-col gap-2 p-2",s),...t})}function qn({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-footer","data-sidebar":"footer",className:L("flex flex-col gap-2 p-2",s),...t})}function Gn({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:L("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",s),...t})}function Jn({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:L("relative flex w-full min-w-0 flex-col p-2",s),...t})}function Qn({className:s,asChild:t=!1,...r}){const d=t?Cs:"div";return e.jsx(d,{"data-slot":"sidebar-group-label","data-sidebar":"group-label",className:L("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",s),...r})}function Wn({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-group-content","data-sidebar":"group-content",className:L("w-full text-sm",s),...t})}function Yn({className:s,...t}){return e.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:L("flex w-full min-w-0 flex-col gap-1",s),...t})}function Xn({className:s,...t}){return e.jsx("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:L("group/menu-item relative",s),...t})}const Zn=qs("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}});function er({asChild:s=!1,isActive:t=!1,variant:r="default",size:d="default",tooltip:u,className:f,...$}){const C=s?Cs:"button",{isMobile:O,state:M}=Mt(),R=e.jsx(C,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":d,"data-active":t,className:L(Zn({variant:r,size:d}),f),...$});return u?(typeof u=="string"&&(u={children:u}),e.jsxs(Ys,{children:[e.jsx(Xs,{asChild:!0,children:R}),e.jsx(Zs,{side:"right",align:"center",hidden:M!=="collapsed"||O,...u})]})):R}const Ls="";class je extends Error{status;body;constructor(t,r,d){super(r),this.status=t,this.body=d}}function sr(s){const t={};if(!s)return t;if(s instanceof Headers)s.forEach((r,d)=>t[d]=r);else if(Array.isArray(s))for(const[r,d]of s)t[r]=d;else Object.assign(t,s);return t}function tr(){const s={},t=localStorage.getItem("access_token");return t&&(s.Authorization=`Bearer ${t}`),s}function ar(){const s=localStorage.getItem("active_org_id");return s?{"X-Org-ID":s}:{}}async function fs(s,t,r,d={}){const f={...{"Content-Type":"application/json"},...d.auth===!1?{}:tr(),...ar(),...sr(d.headers)},$=await fetch(`${Ls}${s}`,{method:t,headers:f,body:r===void 0?void 0:JSON.stringify(r),...d}),O=($.headers.get("content-type")||"").includes("application/json"),M=O?await $.json().catch(()=>{}):await $.text().catch(()=>"");if(!$.ok){const R=O&&M&&typeof M=="object"&&"error"in M&&M.error||O&&M&&typeof M=="object"&&"message"in M&&M.message||typeof M=="string"&&M||`HTTP ${$.status}`;throw new je($.status,String(R),M)}return console.debug("API ->",t,`${Ls}${s}`,f),O?M:void 0}const g={get:(s,t)=>fs(s,"GET",void 0,t),post:(s,t,r)=>fs(s,"POST",t,r),put:(s,t,r)=>fs(s,"PUT",t,r),patch:(s,t,r)=>fs(s,"PATCH",t,r),delete:(s,t)=>fs(s,"DELETE",void 0,t)};function nr(s){return s&&(s.user||s.user_id)}function Ot(s){return nr(s)?.role==="admin"}function rr(s){return(s?.org_role??"")==="admin"}const Ve={isAuthenticated(){return!!localStorage.getItem("access_token")},async login(s,t){const r=await g.post("/api/v1/auth/login",{email:s,password:t});localStorage.setItem("access_token",r.access_token),localStorage.setItem("refresh_token",r.refresh_token)},async register(s,t,r){await g.post("/api/v1/auth/register",{name:s,email:t,password:r})},async me(){return await g.get("/api/v1/auth/me")},async logout(){const s=localStorage.getItem("refresh_token");if(s)try{await g.post("/api/v1/auth/logout",{refresh_token:s})}catch{}localStorage.removeItem("access_token"),localStorage.removeItem("refresh_token")},async forgot(s){await g.post("/api/v1/auth/password/forgot",{email:s})},async reset(s,t){await g.post("/api/v1/auth/password/reset",{token:s,new_password:t})},async verify(s){const t=await fetch(`${Ls}/api/v1/auth/verify?token=${encodeURIComponent(s)}`);if(!t.ok){const r=await t.text();throw new Error(r)}}};function ir({...s}){return e.jsx(wa,{"data-slot":"collapsible",...s})}function or({...s}){return e.jsx(ya,{"data-slot":"collapsible-trigger",...s})}function lr({...s}){return e.jsx(Sa,{"data-slot":"collapsible-content",...s})}function is({...s}){return e.jsx(Ca,{"data-slot":"dropdown-menu",...s})}function os({...s}){return e.jsx(_a,{"data-slot":"dropdown-menu-trigger",...s})}function ls({className:s,sideOffset:t=4,...r}){return e.jsx(ka,{children:e.jsx(Aa,{"data-slot":"dropdown-menu-content",sideOffset:t,className:L("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 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",s),...r})})}function Ie({className:s,inset:t,variant:r="default",...d}){return e.jsx(Ea,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":r,className:L("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),...d})}function dr(){const{setTheme:s,theme:t}=yt();return e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsx(h,{variant:"outline",size:"icon","aria-label":"Toggle theme",children:t==="light"?e.jsx(sn,{className:"h-5 w-5"}):t==="dark"?e.jsx(tn,{className:"h-5 w-5"}):e.jsx(an,{className:"h-5 w-5"})})}),e.jsxs(ls,{align:"end",children:[e.jsxs(Ie,{onClick:()=>s("light"),children:[t==="light"&&e.jsx(bs,{}),"Light"]}),e.jsxs(Ie,{onClick:()=>s("dark"),children:[t==="dark"&&e.jsx(bs,{}),"Dark"]}),e.jsxs(Ie,{onClick:()=>s("system"),children:[t==="system"&&e.jsx(bs,{}),"System"]})]})]})}const Ks="active_org_id",ns="active-org-changed",ys="orgs-changed";function Ke(){return localStorage.getItem(Ks)}function ws(s){s?localStorage.setItem(Ks,s):localStorage.removeItem(Ks),window.dispatchEvent(new CustomEvent(ns,{detail:s}))}function ut(){window.dispatchEvent(new Event(ys))}const cr=()=>{const[s,t]=o.useState([]),[r,d]=o.useState(null);async function u(){try{const C=await g.get("/api/v1/orgs");t(C),!Ke()&&C.length>0&&(ws(C[0].id),d(C[0].id))}catch(C){const O=C instanceof je?C.message:"Failed to load organizations";console.error(O)}}o.useEffect(()=>{d(Ke()),u();const C=R=>{R.key==="active_org_id"&&d(R.newValue)};window.addEventListener("storage",C);const O=R=>d(R.detail??null),M=()=>void u();return window.addEventListener(ns,O),window.addEventListener(ys,M),()=>{window.removeEventListener("storage",C),window.removeEventListener(ns,O),window.removeEventListener(ys,M)}},[]);const f=C=>{ws(C),d(C)},$=s.find(C=>C.id===r)?.name??"Select Org";return e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsx(h,{variant:"outline",className:"w-full justify-start",children:$})}),e.jsx(ls,{className:"w-48",children:s.length===0?e.jsx(Ie,{disabled:!0,children:"No organizations"}):s.map(C=>e.jsx(Ie,{onClick:()=>f(C.id),className:C.id===r?"font-semibold":void 0,children:C.name},C.id))})]})},mr=[{label:"Dashboard",icon:nn,to:"/dashboard"},{label:"Core",icon:cn,items:[{label:"Cluster",to:"/core/clusters",icon:rn},{label:"Node Pools",icon:on,to:"/core/nodepools"},{label:"Annotations",icon:ln,to:"/core/annotations"},{label:"Labels",icon:It,to:"/core/labels"},{label:"Taints",icon:dn,to:"/core/taints"},{label:"Servers",icon:hs,to:"/core/servers"}]},{label:"Security",icon:hn,items:[{label:"Keys & Tokens",icon:mn,to:"/security/keys"},{label:"SSH Keys",to:"/security/ssh",icon:xn}]},{label:"Tasks",icon:un,items:[]},{label:"Settings",icon:gn,items:[{label:"Jobs",icon:jn,to:"/settings/jobs"},{label:"Organizations",to:"/settings/orgs",icon:fn},{label:"Members",to:"/settings/members",icon:mt},{label:"Profile",to:"/settings/me",icon:pn}]},{label:"Admin",icon:vn,requiresAdmin:!0,items:[{label:"Users",to:"/admin/users",icon:mt,requiresAdmin:!0}]}];function zt(s,t,r){return s.filter(d=>!(d.requiresAdmin&&!t||d.requiresOrgAdmin&&!r)).map(d=>({...d,items:d.items?zt(d.items,t,r):void 0})).filter(d=>!d.items||d.items.length>0)}const Ft=({item:s})=>{const t=Ms(),r=s.icon;return s.to?e.jsxs(as,{to:s.to,className:`hover:bg-accent hover:text-accent-foreground flex items-center space-x-2 rounded-md px-4 py-2 text-sm ${t.pathname===s.to?"bg-accent text-accent-foreground":""}`,children:[e.jsx(r,{className:"mr-4 h-4 w-4"}),s.label]}):s.items?e.jsx(ir,{defaultOpen:!0,className:"group/collapsible",children:e.jsxs(Jn,{children:[e.jsx(Qn,{asChild:!0,children:e.jsxs(or,{children:[e.jsx(r,{className:"mr-4 h-4 w-4"}),s.label,e.jsx(Gs,{className:"ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180"})]})}),e.jsx(lr,{children:e.jsx(Wn,{children:e.jsx(Yn,{children:s.items.map((d,u)=>e.jsx(Xn,{children:e.jsx(er,{asChild:!0,children:e.jsx(Ft,{item:d})})},u))})})})]})}):null},xr=()=>{const[s,t]=o.useState(null),[r,d]=o.useState(!0);o.useEffect(()=>{let f=!0;return(async()=>{try{const $=await Ve.me();if(!f)return;t($)}catch{}finally{d(!1)}})(),()=>{f=!1}},[]);const u=o.useMemo(()=>{const f=Ot(s),$=rr(s);return zt(mr,f,$)},[s]);return r?e.jsx("div",{className:"p-6",children:"Loading…"}):e.jsxs(Hn,{children:[e.jsx(Kn,{className:"flex items-center justify-between p-4",children:e.jsx("h1",{className:"text-xl font-bold",children:"AutoGlue"})}),e.jsx(Gn,{children:u.map((f,$)=>e.jsx(Ft,{item:f},$))}),e.jsxs(qn,{className:"space-y-2 p-4",children:[e.jsx(cr,{}),e.jsx(dr,{}),e.jsx(h,{onClick:()=>{localStorage.clear(),window.location.reload()},className:"w-full",children:"Logout"})]})]})};function hr(){return e.jsx("footer",{className:"border-t",children:e.jsxs("div",{className:"container flex flex-col items-center justify-between gap-4 py-10 md:h-24 md:flex-row md:py-0",children:[e.jsx("div",{className:"flex flex-col items-center gap-4 px-8 md:flex-row md:gap-2 md:px-0",children:e.jsxs("p",{className:"text-muted-foreground text-center text-sm leading-loose md:text-left",children:["Built for"," ",e.jsx("a",{href:"https://www.glueops.dev/",target:"_blank",rel:"noreferrer",className:"font-medium underline underline-offset-4",children:"GlueOps"}),". The source code is available on"," ",e.jsx("a",{href:"https://github.com/GlueOps/autoglue",target:"_blank",rel:"noreferrer",className:"font-medium underline underline-offset-4",children:"GitHub"}),"."]})}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsx("a",{href:"https://github.com/GlueOps/autoglue",target:"_blank",rel:"noreferrer",children:e.jsx(bn,{className:"h-5 w-5"})})})]})})}function ur(){return e.jsx("div",{className:"flex h-screen",children:e.jsxs(Bn,{children:[e.jsx(xr,{}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx("main",{className:"flex-1 overflow-auto p-4",children:e.jsx(Js,{})}),e.jsx(hr,{})]})]})})}function jr({children:s}){const t=Ms();return Ve.isAuthenticated()?s?e.jsx(e.Fragment,{children:s}):e.jsx(Js,{}):e.jsx(Qs,{to:"/auth/login",state:{from:t},replace:!0})}function fr({children:s}){const[t,r]=o.useState(!0),[d,u]=o.useState(!1),f=Ms();return o.useEffect(()=>{let $=!0;return(async()=>{try{const C=await Ve.me();if(!$)return;u(Ot(C))}catch{if(!$)return;u(!1)}finally{if(r(!1),!$)return}})(),()=>{$=!1}},[]),t?null:d?s?e.jsx(e.Fragment,{children:s}):e.jsx(Js,{}):e.jsx(Qs,{to:"/403",replace:!0,state:{from:f}})}function et({...s}){return e.jsx($a,{"data-slot":"alert-dialog",...s})}function st({...s}){return e.jsx(La,{"data-slot":"alert-dialog-trigger",...s})}function pr({...s}){return e.jsx(Oa,{"data-slot":"alert-dialog-portal",...s})}function gr({className:s,...t}){return e.jsx(za,{"data-slot":"alert-dialog-overlay",className:L("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",s),...t})}function tt({className:s,...t}){return e.jsxs(pr,{children:[e.jsx(gr,{}),e.jsx(Da,{"data-slot":"alert-dialog-content",className:L("bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",s),...t})]})}function at({className:s,...t}){return e.jsx("div",{"data-slot":"alert-dialog-header",className:L("flex flex-col gap-2 text-center sm:text-left",s),...t})}function nt({className:s,...t}){return e.jsx("div",{"data-slot":"alert-dialog-footer",className:L("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...t})}function rt({className:s,...t}){return e.jsx(Ia,{"data-slot":"alert-dialog-title",className:L("text-lg font-semibold",s),...t})}function it({className:s,...t}){return e.jsx(Ta,{"data-slot":"alert-dialog-description",className:L("text-muted-foreground text-sm",s),...t})}function ot({className:s,...t}){return e.jsx(Ma,{className:L(Ws(),s),...t})}function lt({className:s,...t}){return e.jsx(Pa,{className:L(Ws({variant:"outline"}),s),...t})}function Te({className:s,...t}){return e.jsx("div",{"data-slot":"card",className:L("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",s),...t})}function Pe({className:s,...t}){return e.jsx("div",{"data-slot":"card-header",className:L("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",s),...t})}function Be({className:s,...t}){return e.jsx("div",{"data-slot":"card-title",className:L("leading-none font-semibold",s),...t})}function Me({className:s,...t}){return e.jsx("div",{"data-slot":"card-content",className:L("px-6",s),...t})}function Ss({className:s,...t}){return e.jsx("div",{"data-slot":"card-footer",className:L("flex items-center px-6 [.border-t]:pt-6",s),...t})}function ie({...s}){return e.jsx(Ct,{"data-slot":"dialog",...s})}function We({...s}){return e.jsx(Fa,{"data-slot":"dialog-trigger",...s})}function vr({...s}){return e.jsx($t,{"data-slot":"dialog-portal",...s})}function br({className:s,...t}){return e.jsx(Lt,{"data-slot":"dialog-overlay",className:L("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",s),...t})}function oe({className:s,children:t,showCloseButton:r=!0,...d}){return e.jsxs(vr,{"data-slot":"dialog-portal",children:[e.jsx(br,{}),e.jsxs(_t,{"data-slot":"dialog-content",className:L("bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",s),...d,children:[t,r&&e.jsxs(kt,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(Dt,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function le({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-header",className:L("flex flex-col gap-2 text-center sm:text-left",s),...t})}function de({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-footer",className:L("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...t})}function ce({className:s,...t}){return e.jsx(At,{"data-slot":"dialog-title",className:L("text-lg leading-none font-semibold",s),...t})}function Ds({className:s,...t}){return e.jsx(Et,{"data-slot":"dialog-description",className:L("text-muted-foreground text-sm",s),...t})}function Nr({className:s,...t}){return e.jsx(Ra,{"data-slot":"label",className:L("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",s),...t})}const ne=la,Rt=o.createContext({}),v=({...s})=>e.jsx(Rt.Provider,{value:{name:s.name},children:e.jsx(da,{...s})}),zs=()=>{const s=o.useContext(Rt),t=o.useContext(Vt),{getFieldState:r}=ca(),d=ma({name:s.name}),u=r(s.name,d);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:f}=t;return{id:f,name:s.name,formItemId:`${f}-form-item`,formDescriptionId:`${f}-form-item-description`,formMessageId:`${f}-form-item-message`,...u}},Vt=o.createContext({});function b({className:s,...t}){const r=o.useId();return e.jsx(Vt.Provider,{value:{id:r},children:e.jsx("div",{"data-slot":"form-item",className:L("grid gap-2",s),...t})})}function N({className:s,...t}){const{error:r,formItemId:d}=zs();return e.jsx(Nr,{"data-slot":"form-label","data-error":!!r,className:L("data-[error=true]:text-destructive",s),htmlFor:d,...t})}function E({...s}){const{error:t,formItemId:r,formDescriptionId:d,formMessageId:u}=zs();return e.jsx(Cs,{"data-slot":"form-control",id:r,"aria-describedby":t?`${d} ${u}`:`${d}`,"aria-invalid":!!t,...s})}function jt({className:s,...t}){const{formDescriptionId:r}=zs();return e.jsx("p",{"data-slot":"form-description",id:r,className:L("text-muted-foreground text-sm",s),...t})}function w({className:s,...t}){const{error:r,formMessageId:d}=zs(),u=r?String(r?.message??""):t.children;return u?e.jsx("p",{"data-slot":"form-message",id:d,className:L("text-destructive text-sm",s),...t,children:u}):null}function Ae({...s}){return e.jsx(Va,{"data-slot":"select",...s})}function Ee({...s}){return e.jsx(Ha,{"data-slot":"select-value",...s})}function $e({className:s,size:t="default",children:r,...d}){return e.jsxs(Ua,{"data-slot":"select-trigger","data-size":t,className:L("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",s),...d,children:[r,e.jsx(Ba,{asChild:!0,children:e.jsx(Gs,{className:"size-4 opacity-50"})})]})}function Le({className:s,children:t,position:r="popper",...d}){return e.jsx(Ka,{children:e.jsxs(qa,{"data-slot":"select-content",className:L("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",r==="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",s),position:r,...d,children:[e.jsx(wr,{}),e.jsx(Ga,{className:L("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),e.jsx(yr,{})]})})}function ve({className:s,children:t,...r}){return e.jsxs(Ja,{"data-slot":"select-item",className:L("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",s),...r,children:[e.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:e.jsx(Qa,{children:e.jsx(bs,{className:"size-4"})})}),e.jsx(Wa,{children:t})]})}function wr({className:s,...t}){return e.jsx(Ya,{"data-slot":"select-scroll-up-button",className:L("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(Nn,{className:"size-4"})})}function yr({className:s,...t}){return e.jsx(Xa,{"data-slot":"select-scroll-down-button",className:L("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(Gs,{className:"size-4"})})}const Sr=re({name:F().min(1,"Name required"),email:js("Enter a valid email"),role:Je(["user","admin"]),password:F().min(8,"Min 8 characters")}),Cr=re({name:F().min(1,"Name required"),email:js("Enter a valid email"),role:Je(["user","admin"]),password:F().min(8,"Min 8 characters").optional().or(St(""))});function _r(){const[s,t]=o.useState([]),[r,d]=o.useState(!0),[u,f]=o.useState(!1),[$,C]=o.useState(!1),[O,M]=o.useState(null),[R,U]=o.useState(null),T=te({resolver:ae(Sr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}}),P=te({resolver:ae(Cr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}});async function j(){d(!0);try{const c=await g.get("/api/v1/admin/users?page=1&page_size=100");t(c.users??[])}catch(c){ee.error(c instanceof je?c.message:"Failed to load users")}finally{d(!1)}}o.useEffect(()=>{j()},[]);async function V(c){try{const S=await g.post("/api/v1/admin/users",c);t(G=>[S,...G]),f(!1),T.reset({name:"",email:"",role:"user",password:""}),ee.success(`Created ${S.email}`)}catch(S){ee.error(S instanceof je?S.message:"Failed to create user")}}function H(c){M(c),P.reset({name:c.name||"",email:c.email,role:c.role??"user",password:""}),C(!0)}async function m(c){if(!O)return;const S={name:c.name,email:c.email,role:c.role};c.password&&c.password.length>=8&&(S.password=c.password);try{const G=await g.patch(`/api/v1/admin/users/${O.id}`,S);t(K=>K.map(B=>B.id===G.id?G:B)),C(!1),M(null),ee.success(`Updated ${G.email}`)}catch(G){ee.error(G instanceof je?G.message:"Failed to update user")}}async function x(c){try{U(c),await g.delete(`/api/v1/admin/users/${c}`),t(S=>S.filter(G=>G.id!==c)),ee.success("User deleted")}catch(S){ee.error(S instanceof je?S.message:"Failed to delete user")}finally{U(null)}}return e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Users"}),e.jsxs(h,{onClick:()=>f(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"}),"New user"]})]}),e.jsx(Ns,{}),r?e.jsx("div",{className:"text-muted-foreground text-sm",children:"Loading…"}):s.length===0?e.jsx("div",{className:"text-muted-foreground text-sm",children:"No users yet."}):e.jsx("div",{className:"grid grid-cols-1 gap-4 pr-2 md:grid-cols-2 lg:grid-cols-3",children:s.map(c=>e.jsxs(Te,{className:"flex flex-col",children:[e.jsx(Pe,{children:e.jsx(Be,{className:"text-base",children:c.name||c.email})}),e.jsxs(Me,{className:"text-muted-foreground space-y-1 text-sm",children:[e.jsxs("div",{children:["Email: ",c.email]}),e.jsxs("div",{children:["Role: ",c.role]}),e.jsxs("div",{children:["Verified: ",c.email_verified?"Yes":"No"]}),e.jsxs("div",{children:["Joined: ",new Date(c.created_at).toLocaleString()]})]}),e.jsxs(Ss,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(h,{variant:"outline",onClick:()=>H(c),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(et,{children:[e.jsx(st,{asChild:!0,children:e.jsxs(h,{variant:"destructive",disabled:R===c.id,children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"}),R===c.id?"Deleting…":"Delete"]})}),e.jsxs(tt,{children:[e.jsxs(at,{children:[e.jsx(rt,{children:"Delete user?"}),e.jsxs(it,{children:["This will permanently delete ",e.jsx("b",{children:c.email}),"."]})]}),e.jsxs(nt,{className:"sm:justify-between",children:[e.jsx(lt,{disabled:R===c.id,children:"Cancel"}),e.jsx(ot,{asChild:!0,disabled:R===c.id,children:e.jsx(h,{variant:"destructive",onClick:()=>x(c.id),children:"Confirm delete"})})]})]})]})]})]},c.id))}),e.jsx(ie,{open:u,onOpenChange:f,children:e.jsxs(oe,{className:"sm:max-w-[520px]",children:[e.jsxs(le,{children:[e.jsx(ce,{children:"Create user"}),e.jsx(Ds,{children:"Add a new user account."})]}),e.jsx(ne,{...T,children:e.jsxs("form",{onSubmit:T.handleSubmit(V),className:"grid gap-4 py-2",children:[e.jsx(v,{name:"name",control:T.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{...c,placeholder:"Jane Doe"})}),e.jsx(w,{})]})}),e.jsx(v,{name:"email",control:T.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{type:"email",...c,placeholder:"jane@example.com"})}),e.jsx(w,{})]})}),e.jsx(v,{name:"role",control:T.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Ae,{value:c.value,onValueChange:c.onChange,children:[e.jsx(E,{children:e.jsx($e,{className:"w-[200px]",children:e.jsx(Ee,{placeholder:"Select role"})})}),e.jsxs(Le,{children:[e.jsx(ve,{value:"user",children:"User"}),e.jsx(ve,{value:"admin",children:"Admin"})]})]}),e.jsx(w,{})]})}),e.jsx(v,{name:"password",control:T.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Password"}),e.jsx(E,{children:e.jsx(z,{type:"password",...c,placeholder:"••••••••"})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>f(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!T.formState.isValid||T.formState.isSubmitting,children:T.formState.isSubmitting?"Creating…":"Create"})]})]})})]})}),e.jsx(ie,{open:$,onOpenChange:C,children:e.jsxs(oe,{className:"sm:max-w-[520px]",children:[e.jsxs(le,{children:[e.jsx(ce,{children:"Edit user"}),e.jsx(Ds,{children:"Update user details. Leave password blank to keep it unchanged."})]}),e.jsx(ne,{...P,children:e.jsxs("form",{onSubmit:P.handleSubmit(m),className:"grid gap-4 py-2",children:[e.jsx(v,{name:"name",control:P.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{...c})}),e.jsx(w,{})]})}),e.jsx(v,{name:"email",control:P.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{type:"email",...c})}),e.jsx(w,{})]})}),e.jsx(v,{name:"role",control:P.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Ae,{value:c.value,onValueChange:c.onChange,children:[e.jsx(E,{children:e.jsx($e,{className:"w-[200px]",children:e.jsx(Ee,{placeholder:"Select role"})})}),e.jsxs(Le,{children:[e.jsx(ve,{value:"user",children:"User"}),e.jsx(ve,{value:"admin",children:"Admin"})]})]}),e.jsx(w,{})]})}),e.jsx(v,{name:"password",control:P.control,render:({field:c})=>e.jsxs(b,{children:[e.jsx(N,{children:"New password (optional)"}),e.jsx(E,{children:e.jsx(z,{type:"password",...c,placeholder:"Leave blank to keep"})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>C(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!P.formState.isValid||P.formState.isSubmitting,children:P.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})}const kr=re({email:js()});function Ar(){const s=te({resolver:ae(kr),defaultValues:{email:""}});async function t(r){try{await Ve.forgot(r.email),ee.success("If that email exists, we've sent instructions.")}catch(d){ee.error(d.message||"Something went wrong")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"Forgot password"})}),e.jsx(Me,{children:e.jsx(ne,{...s,children:e.jsxs("form",{onSubmit:s.handleSubmit(t),className:"space-y-4",children:[e.jsx(v,{name:"email",control:s.control,render:({field:r})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{placeholder:"you@example.com",...r})}),e.jsx(w,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Send reset link"})]})})})]})})}const Er=re({email:js(),password:F().min(6)});function $r(){const s=_s(),t=Ms(),r=te({resolver:ae(Er),defaultValues:{email:"",password:""}});async function d(u){try{await Ve.login(u.email,u.password),ee.success("Welcome back!");const f=t.state?.from?.pathname??"/settings/me";s(f,{replace:!0})}catch(f){ee.error(f.message||"Login failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"Sign in"})}),e.jsxs(Me,{children:[e.jsx(ne,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(d),className:"space-y-4",children:[e.jsx(v,{name:"email",control:r.control,render:({field:u})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{placeholder:"you@example.com",...u})}),e.jsx(w,{})]})}),e.jsx(v,{name:"password",control:r.control,render:({field:u})=>e.jsxs(b,{children:[e.jsx(N,{children:"Password"}),e.jsx(E,{children:e.jsx(z,{type:"password",placeholder:"••••••••",...u})}),e.jsx(w,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Sign in"})]})}),e.jsxs("div",{className:"mt-4 flex justify-between text-sm",children:[e.jsx(as,{to:"/auth/forgot",className:"underline",children:"Forgot password?"}),e.jsx(as,{to:"/auth/register",className:"underline",children:"Create an account"})]})]})]})})}function Lr(){const[s,t]=o.useState(null),r=_s();o.useEffect(()=>{(async()=>{try{const u=await Ve.me();t(u)}catch(u){ee.error(u.message||"Failed to load profile")}})()},[]);async function d(){await Ve.logout(),r("/auth/login")}return e.jsx("div",{className:"mx-auto max-w-xl",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"My Account"})}),e.jsxs(Me,{className:"space-y-3",children:[s?e.jsx("pre",{className:"bg-muted overflow-auto rounded p-3 text-sm",children:JSON.stringify(s,null,2)}):e.jsx("p",{children:"Loading…"}),e.jsx(h,{onClick:d,children:"Sign out"})]})]})})}const Dr=re({name:F().min(2),email:js(),password:F().min(6)});function Ir(){const s=_s(),t=te({resolver:ae(Dr),defaultValues:{name:"",email:"",password:""}});async function r(d){try{await Ve.register(d.name,d.email,d.password),ee.success("Account created! Check your email to verify."),s("/auth/login")}catch(u){ee.error(u.message||"Registration failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"Create account"})}),e.jsxs(Me,{children:[e.jsx(ne,{...t,children:e.jsxs("form",{onSubmit:t.handleSubmit(r),className:"space-y-4",children:[e.jsx(v,{name:"name",control:t.control,render:({field:d})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"Jane Doe",...d})}),e.jsx(w,{})]})}),e.jsx(v,{name:"email",control:t.control,render:({field:d})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{placeholder:"you@example.com",...d})}),e.jsx(w,{})]})}),e.jsx(v,{name:"password",control:t.control,render:({field:d})=>e.jsxs(b,{children:[e.jsx(N,{children:"Password"}),e.jsx(E,{children:e.jsx(z,{type:"password",placeholder:"••••••••",...d})}),e.jsx(w,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Create account"})]})}),e.jsxs("div",{className:"mt-4 text-sm",children:["Already have an account?"," ",e.jsx(as,{to:"/auth/login",className:"underline",children:"Sign in"})]})]})]})})}const Tr=re({new_password:F().min(6)});function Pr(){const[s]=Tt(),t=s.get("token"),r=te({resolver:ae(Tr),defaultValues:{new_password:""}}),d=_s();async function u(f){if(!t){ee.error("Missing token");return}try{await Ve.reset(t,f.new_password),ee.success("Password updated. Please sign in."),d("/auth/login")}catch($){ee.error($.message||"Reset failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"Reset password"})}),e.jsxs(Me,{children:[e.jsx(ne,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(u),className:"space-y-4",children:[e.jsx(v,{name:"new_password",control:r.control,render:({field:f})=>e.jsxs(b,{children:[e.jsx(N,{children:"New password"}),e.jsx(E,{children:e.jsx(z,{type:"password",placeholder:"••••••••",...f})}),e.jsx(w,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Update password"})]})}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsx(as,{to:"/auth/login",className:"underline",children:"Back to sign in"})})]})]})})}function Mr(){const[s]=Tt(),t=s.get("token"),[r,d]=o.useState("idle");return o.useEffect(()=>{async function u(){if(!t){d("error");return}try{await Ve.verify(t),d("ok")}catch(f){ee.error(f.message||"Verification failed"),d("error")}}u()},[t]),e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:"Email verification"})}),e.jsxs(Me,{className:"space-y-3",children:[r==="idle"&&e.jsx("p",{children:"Verifying…"}),r==="ok"&&e.jsxs("div",{children:[e.jsx("p",{children:"Your email has been verified. You can now sign in."}),e.jsx(h,{asChild:!0,className:"mt-3",children:e.jsx(as,{to:"/auth/login",children:"Go to sign in"})})]}),r==="error"&&e.jsxs("div",{children:[e.jsx("p",{children:"Verification failed. Please request a new verification email."}),e.jsx(h,{asChild:!0,className:"mt-3",children:e.jsx(as,{to:"/auth/login",children:"Back to sign in"})})]})]})]})})}const Or=qs("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function Ce({className:s,variant:t,asChild:r=!1,...d}){const u=r?Cs:"span";return e.jsx(u,{"data-slot":"badge",className:L(Or({variant:t}),s),...d})}function De({className:s,...t}){return e.jsx(Za,{"data-slot":"checkbox",className:L("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...t,children:e.jsx(en,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(bs,{className:"size-3.5"})})})}function be({className:s,...t}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:L("w-full caption-bottom text-sm",s),...t})})}function Ne({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:L("[&_tr]:border-b",s),...t})}function we({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:L("[&_tr:last-child]:border-0",s),...t})}function q({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:L("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t})}function A({className:s,...t}){return e.jsx("th",{"data-slot":"table-head",className:L("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function p({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:L("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}const zr=re({key:F().trim().min(1,"Key is required").max(120,"Max 120 chars"),value:F().trim().min(1,"Value is required").max(512,"Max 512 chars"),node_pool_ids:Oe(F().uuid()).optional().default([])}),Fr=re({key:F().trim().min(1,"Key is required").max(120,"Max 120 chars"),value:F().trim().min(1,"Value is required").max(512,"Max 512 chars")}),Rr=re({node_pool_ids:Oe(F().uuid()).min(1,"Pick at least one node pool")});function ft(s,t=12){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}const Vr=()=>{const[s,t]=o.useState(!0),[r,d]=o.useState(null),[u,f]=o.useState([]),[$,C]=o.useState([]),[O,M]=o.useState(""),[R,U]=o.useState(!1),[T,P]=o.useState(null),[j,V]=o.useState(null),[H,m]=o.useState([]),[x,c]=o.useState(!1),[S,G]=o.useState(null);async function K(){t(!0),d(null);try{const[y,Y]=await Promise.all([g.get("/api/v1/annotations?include=node_pools"),g.get("/api/v1/node-pools")]);if(f(y||[]),C(Y||[]),T){const he=(y||[]).find(i=>i.id===T.id)||null;P(he)}if(j){const he=(y||[]).find(i=>i.id===j.id)||null;V(he),he&&B(he.id)}}catch(y){console.error(y);const Y=y instanceof je?y.message:"Failed to load annotations / node pools";d(Y)}finally{t(!1)}}async function B(y){c(!0),G(null);try{const Y=await g.get(`/api/v1/annotations/${y}/node_pools`);m(Y||[])}catch(Y){console.error(Y);const he=Y instanceof je?Y.message:"Failed to load pools for annotation";G(he)}finally{c(!1)}}o.useEffect(()=>{K()},[]);const xe=o.useMemo(()=>{const y=O.trim().toLowerCase();return y?u.filter(Y=>Y.key.toLowerCase().includes(y)||Y.value.toLowerCase().includes(y)||(Y.node_pools||[]).some(he=>he.name.toLowerCase().includes(y))):u},[u,O]);async function W(y){confirm("Delete this annotation? This cannot be undone.")&&(await g.delete(`/api/v1/annotations/${y}`),await K())}const ue=te({resolver:ae(zr),defaultValues:{key:"",value:"",node_pool_ids:[]}}),fe=async y=>{const Y={key:y.key.trim(),value:y.value.trim()};y.node_pool_ids&&y.node_pool_ids.length>0&&(Y.node_pool_ids=y.node_pool_ids),await g.post("/api/v1/annotations",Y),U(!1),ue.reset({key:"",value:"",node_pool_ids:[]}),await K()},a=te({resolver:ae(Fr),defaultValues:{key:"",value:""}});function n(y){P(y),a.reset({key:y.key,value:y.value})}const _=async y=>{T&&(await g.patch(`/api/v1/annotations/${T.id}`,{name:y.key.trim(),value:y.value.trim()}),P(null),await K())},X=te({resolver:ae(Rr),defaultValues:{node_pool_ids:[]}});function me(y){V(y),X.reset({node_pool_ids:[]}),B(y.id)}const ge=async y=>{j&&(await g.post(`/api/v1/annotations/${j.id}/node_pools`,{node_pool_ids:y.node_pool_ids}),X.reset({node_pool_ids:[]}),await B(j.id),await K())};async function Re(y){j&&confirm("Detach this node pool from the annotation?")&&(await g.delete(`/api/v1/annotations/${j.id}/node_pools/${y}`),await B(j.id),await K())}return s?e.jsx("div",{className:"p-6",children:"Loading annotations…"}):r?e.jsx("div",{className:"p-6 text-red-500",children:r}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Annotations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ts,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(z,{value:O,onChange:y=>M(y.target.value),placeholder:"Search name, value, pool…",className:"w-72 pl-8"})]}),e.jsxs(h,{variant:"outline",onClick:K,children:[e.jsx(Ps,{className:"mr-2 h-4 w-4"})," Refresh"]}),e.jsxs(ie,{open:R,onOpenChange:U,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>U(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"})," Create Annotation"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create annotation"})}),e.jsx(ne,{...ue,children:e.jsxs("form",{onSubmit:ue.handleSubmit(fe),className:"space-y-4",children:[e.jsx(v,{control:ue.control,name:"key",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key"}),e.jsx(E,{children:e.jsx(z,{placeholder:"cluster-autoscaler.kubernetes.io/safe-to-evict",...y})}),e.jsx(w,{})]})}),e.jsx(v,{control:ue.control,name:"value",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Value"}),e.jsx(E,{children:e.jsx(z,{placeholder:"true",...y})}),e.jsx(w,{})]})}),e.jsx(v,{control:ue.control,name:"node_pool_ids",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Initial node pools (optional)"}),e.jsxs("div",{className:"max-h-56 space-y-2 overflow-auto rounded-xl border p-2",children:[$.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No node pools available"}),$.map(Y=>{const he=y.value?.includes(Y.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:he,onCheckedChange:i=>{const D=new Set(y.value||[]);i===!0?D.add(Y.id):D.delete(Y.id),y.onChange(Array.from(D))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:Y.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ft(Y.id,8)})]})]},Y.id)})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>U(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:ue.formState.isSubmitting,children:ue.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Key"}),e.jsx(A,{children:"Value"}),e.jsx(A,{children:"Node Pools"}),e.jsx(A,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[xe.map(y=>{const Y=y.node_pools||[];return e.jsxs(q,{children:[e.jsx(p,{className:"font-mono text-sm",children:y.key}),e.jsx(p,{className:"font-mono text-sm",children:y.value}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[Y.slice(0,6).map(he=>e.jsxs(Ce,{variant:"secondary",className:"gap-1",children:[e.jsx(hs,{className:"h-3 w-3"})," ",he.name]},he.id)),Y.length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No node pools"}),Y.length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",Y.length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>me(y),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage Node Pools"]})]}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>n(y),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(ls,{align:"end",children:e.jsx(Ie,{onClick:()=>W(y.id),children:"Confirm delete"})})]})]})})]},y.id)}),xe.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:4,className:"text-muted-foreground py-10 text-center",children:"No annotations match your search."})})]})]})})}),e.jsx(ie,{open:!!T,onOpenChange:y=>!y&&P(null),children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsx(le,{children:e.jsx(ce,{children:"Edit annotation"})}),e.jsx(ne,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(_),className:"space-y-4",children:[e.jsx(v,{control:a.control,name:"key",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key"}),e.jsx(E,{children:e.jsx(z,{placeholder:"example.com/some",...y})}),e.jsx(w,{})]})}),e.jsx(v,{control:a.control,name:"value",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Value"}),e.jsx(E,{children:e.jsx(z,{placeholder:"true",...y})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>P(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:a.formState.isSubmitting,children:a.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ie,{open:!!j,onOpenChange:y=>!y&&V(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage node pools for ",e.jsx("span",{className:"font-mono",children:j?.key})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached node pools"}),x?e.jsx("div",{className:"text-muted-foreground rounded-md border p-3 text-sm",children:"Loading…"}):S?e.jsx("div",{className:"rounded-md border p-3 text-sm text-red-500",children:S}):e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[H.map(y=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:y.name}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>Re(y.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},y.id)),H.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:2,className:"text-muted-foreground py-8 text-center",children:"No node pools attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...X,children:e.jsxs("form",{onSubmit:X.handleSubmit(ge),className:"space-y-3",children:[e.jsx(v,{control:X.control,name:"node_pool_ids",render:({field:y})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more node pools"}),e.jsx("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:(()=>{const Y=new Set(H.map(i=>i.id)),he=$.filter(i=>!Y.has(i.id));return he.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more node pools available to attach"}):he.map(i=>{const D=y.value?.includes(i.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:D,onCheckedChange:ze=>{const Fe=new Set(y.value||[]);ze===!0?Fe.add(i.id):Fe.delete(i.id),y.onChange(Array.from(Fe))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:i.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ft(i.id,8)})]})]},i.id)})})()}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:X.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",X.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})};function cs({className:s,...t}){return e.jsx("textarea",{"data-slot":"textarea",className:L("border-input placeholder: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 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),...t})}const Ur=re({name:F().trim().min(2,"Name is too short"),provider:F().trim().min(2,"Provider is too short"),region:F().trim().min(1,"Region is required"),node_pool_ids:Oe(us()).default([]).optional(),bastion_server_id:us().optional(),cluster_load_balancer:F().optional(),control_load_balancer:F().optional(),kubeconfig:F().optional()}),Br=re({name:F().trim().min(2,"Name is too short").optional(),provider:F().trim().min(2,"Provider is too short").optional(),region:F().trim().min(1,"Region is required").optional(),status:F().trim().min(1,"Status is required").optional(),bastion_server_id:us().or(St("")).optional(),cluster_load_balancer:F().optional(),control_load_balancer:F().optional(),kubeconfig:F().optional()}).refine(s=>s.name!==void 0||s.provider!==void 0||s.region!==void 0||s.status!==void 0||s.bastion_server_id!==void 0||s.cluster_load_balancer!==void 0||s.control_load_balancer!==void 0||s.kubeconfig!==void 0,{message:"Provide at least one change",path:["name"]}),Hr=re({node_pool_ids:Oe(F().uuid()).min(1,"Pick at least one node pool")}),Kr=re({server_id:us({message:"Enter a valid Server UUID"})});function ps(s,t=8){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}function qr(){const[s,t]=o.useState([]),[r,d]=o.useState([]),[u,f]=o.useState([]),[$,C]=o.useState(!1),[O,M]=o.useState(null),[R,U]=o.useState(""),[T,P]=o.useState(!1),[j,V]=o.useState(!1),[H,m]=o.useState(null),[x,c]=o.useState(null),[S,G]=o.useState(null);async function K(){C(!0),M(null);try{const i=`/api/v1/clusters?include=node_pools,bastion${R?`&q=${encodeURIComponent(R)}`:""}`,[D,ze,Fe]=await Promise.all([g.get(i),g.get("/api/v1/node-pools"),g.get("/api/v1/servers?role=bastion").catch(()=>[])]),Se=(D||[]).map(pe=>({id:pe.id,name:pe.name,provider:pe.provider,region:pe.region,status:pe.status,cluster_load_balancer:pe.cluster_load_balancer,control_load_balancer:pe.control_load_balancer,node_pools:pe.node_pools??[],bastion_server:pe.bastion_server??null}));if(t(Se),d(ze||[]),f(Fe||[]),x){const pe=Se.find(He=>He.id===x.id)||null;c(pe)}if(S){const pe=Se.find(He=>He.id===S.id)||null;G(pe)}if(H){const pe=Se.find(He=>He.id===H.id)||null;m(pe)}}catch(i){console.error(i);const D=i instanceof je?i.message:"Failed to load clusters";M(D)}finally{C(!1)}}o.useEffect(()=>{K()},[]);const B=te({resolver:ae(Ur),defaultValues:{name:"",provider:"",region:"",node_pool_ids:[],bastion_server_id:void 0,cluster_load_balancer:"",control_load_balancer:"",kubeconfig:""}}),xe=async i=>{const D={name:i.name.trim(),provider:i.provider.trim(),region:i.region.trim(),node_pool_ids:i.node_pool_ids||[]};i.bastion_server_id&&(D.bastion_server_id=i.bastion_server_id),i.cluster_load_balancer&&(D.cluster_load_balancer=i.cluster_load_balancer),i.control_load_balancer&&(D.control_load_balancer=i.control_load_balancer),i.kubeconfig&&i.kubeconfig.trim()&&(D.kubeconfig=i.kubeconfig.trim()),await g.post("/api/v1/clusters",D),P(!1),B.reset(),await K()},W=te({resolver:ae(Br),defaultValues:{name:void 0,provider:void 0,region:void 0,status:void 0,bastion_server_id:void 0,cluster_load_balancer:void 0,control_load_balancer:void 0,kubeconfig:void 0}});function ue(i){m(i),W.reset({name:void 0,provider:void 0,region:void 0,status:void 0,bastion_server_id:void 0,cluster_load_balancer:void 0,control_load_balancer:void 0}),V(!0)}const fe=async i=>{if(!H)return;const D={};i.name!==void 0&&(D.name=i.name.trim()),i.provider!==void 0&&(D.provider=i.provider.trim()),i.region!==void 0&&(D.region=i.region.trim()),i.status!==void 0&&(D.status=i.status.trim()),i.bastion_server_id!==void 0&&(D.bastion_server_id=i.bastion_server_id||""),i.cluster_load_balancer!==void 0&&(D.cluster_load_balancer=i.cluster_load_balancer),i.control_load_balancer!==void 0&&(D.control_load_balancer=i.control_load_balancer),i.kubeconfig!==void 0&&i.kubeconfig.trim()&&(D.kubeconfig=i.kubeconfig.trim()),await g.patch(`/api/v1/clusters/${H.id}`,D),V(!1),m(null),await K()};async function a(i){confirm("Delete this cluster? This cannot be undone.")&&(await g.delete(`/api/v1/clusters/${i}`),await K())}const n=te({resolver:ae(Hr),defaultValues:{node_pool_ids:[]}});function _(i){c(i),n.reset({node_pool_ids:[]})}const X=async i=>{x&&(await g.post(`/api/v1/clusters/${x.id}/node_pools`,{node_pool_ids:i.node_pool_ids}),n.reset({node_pool_ids:[]}),await K())};async function me(i,D){confirm("Detach selected node pool?")&&(await g.delete(`/api/v1/clusters/${i}/node_pools/${D}`),await K())}const ge=o.useMemo(()=>{if(!x)return[];const i=new Set((x.node_pools||[]).map(D=>D.id));return r.filter(D=>!i.has(D.id))},[x,r]),Re=te({resolver:ae(Kr),defaultValues:{server_id:""}});function y(i){G(i),Re.reset({server_id:""})}const Y=async i=>{S&&(await g.post(`/api/v1/clusters/${S.id}/bastion`,{server_id:i.server_id}),await K())};async function he(){S&&confirm("Clear bastion for this cluster?")&&(await g.delete(`/api/v1/clusters/${S.id}/bastion`),await K())}return $?e.jsx("div",{className:"p-6",children:"Loading clusters…"}):O?e.jsx("div",{className:"p-6 text-red-500",children:O}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Clusters"}),e.jsxs("div",{className:"flex flex-1 items-center gap-2 md:justify-end",children:[e.jsx(z,{className:"max-w-xs",placeholder:"Filter by name…",value:R,onChange:i=>U(i.target.value),onKeyDown:i=>{i.key==="Enter"&&K()}}),e.jsxs(h,{variant:"outline",onClick:()=>void K(),children:[e.jsx(wn,{className:"mr-2 h-4 w-4"}),"Apply"]}),e.jsxs(ie,{open:T,onOpenChange:P,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>P(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"}),"Create Cluster"]})}),e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create Cluster"})}),e.jsx(ne,{...B,children:e.jsxs("form",{onSubmit:B.handleSubmit(xe),className:"grid gap-4 md:grid-cols-2",children:[e.jsx(v,{control:B.control,name:"name",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"my-eks-prod",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"provider",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"Provider"}),e.jsx(E,{children:e.jsx(z,{placeholder:"aws|gcp|azure|onprem",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"region",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"Region"}),e.jsx(E,{children:e.jsx(z,{placeholder:"eu-west-1",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"bastion_server_id",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"Bastion server (UUID, optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:"paste server UUID",...i})}),u.length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Suggestions:",e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:u.slice(0,6).map(D=>e.jsxs(h,{type:"button",size:"sm",variant:i.value===D.id?"default":"outline",onClick:()=>i.onChange(D.id),className:"font-normal",children:[e.jsx(hs,{className:"mr-1 h-3 w-3"})," ",D.hostname||ps(D.id,6)]},D.id))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"cluster_load_balancer",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Cluster Load Balancer (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:"e.g. JSON or URL or ARN",rows:2,...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"control_load_balancer",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Control Load Balancer (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:"e.g. JSON or URL or ARN",rows:2,...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"node_pool_ids",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Attach node pools (optional)"}),e.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:[r.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No node pools available"}),r.map(D=>{const ze=i.value?.includes(D.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:ze,onCheckedChange:Fe=>{const Se=new Set(i.value||[]);Fe===!0?Se.add(D.id):Se.delete(D.id),i.onChange(Array.from(Se))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:D.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ps(D.id,8)})]})]},D.id)})]}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"kubeconfig",render:({field:i})=>e.jsxs(b,{className:"md:colspan-2",children:[e.jsx(N,{children:"Kubeconfig (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:"Paste full kubeconfig YAML here. It will be encrypted and never returned by the API.",rows:8,className:"font-mono",...i})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"md:col-span-2 gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>P(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:B.formState.isSubmitting,children:B.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{children:"Provider / Region"}),e.jsx(A,{children:"Status"}),e.jsx(A,{children:"Node Pools"}),e.jsx(A,{children:"Bastion"}),e.jsx(A,{className:"w-[360px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[s.map(i=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:i.name}),e.jsxs(p,{children:[e.jsx("div",{className:"text-sm font-medium",children:i.provider||"—"}),e.jsx("div",{className:"text-muted-foreground text-xs",children:i.region||"—"})]}),e.jsx(p,{children:e.jsx(Ce,{variant:i.status==="ready"?"default":i.status==="error"?"destructive":"secondary",children:i.status||"unknown"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex max-w-[280px] flex-wrap gap-2",children:[(i.node_pools||[]).slice(0,4).map(D=>e.jsx(Ce,{variant:"secondary",children:D.name},D.id)),(i.node_pools||[]).length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No pools"}),(i.node_pools||[]).length>4&&e.jsxs("span",{className:"text-muted-foreground",children:["+",(i.node_pools||[]).length-4," more"]})]})}),e.jsx(p,{children:i.bastion_server?e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:i.bastion_server.hostname||ps(i.bastion_server.id,6)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:i.bastion_server.ip})]}):e.jsx("span",{className:"text-muted-foreground",children:"None"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>_(i),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage pools"]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>y(i),children:[e.jsx(hs,{className:"mr-2 h-4 w-4"})," Bastion"]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>ue(i),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>a(i.id),children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"})," Delete"]})]})})]},i.id)),s.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:6,className:"text-muted-foreground py-10 text-center",children:"No clusters yet."})})]})]})})}),e.jsx(ie,{open:j,onOpenChange:i=>!i&&V(!1),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Edit Cluster",H?e.jsxs("span",{className:"text-muted-foreground ml-2 font-mono text-sm",children:["(",H.name,")"]}):null]})}),e.jsx(ne,{...W,children:e.jsxs("form",{onSubmit:W.handleSubmit(fe),className:"grid gap-4 md:grid-cols-2",children:[e.jsx(v,{control:W.control,name:"name",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"New name (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:H?.name||"e.g. my-eks-prod",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"provider",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"New provider (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:H?.provider||"aws",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"region",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"New region (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:H?.region||"eu-west-1",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"status",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"New status (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:H?.status||"pending|ready|error",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"bastion_server_id",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Replace/clear bastion (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:"paste new server UUID or leave blank to clear",...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"cluster_load_balancer",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Cluster Load Balancer (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:H?.cluster_load_balancer||"e.g. JSON or URL or ARN",rows:2,...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"control_load_balancer",render:({field:i})=>e.jsxs(b,{className:"md:col-span-2",children:[e.jsx(N,{children:"Control Load Balancer (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:H?.control_load_balancer||"e.g. JSON or URL or ARN",rows:2,...i})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"kubeconfig",render:({field:i})=>e.jsxs(b,{className:"md:colspan-2",children:[e.jsx(N,{children:"Replace Kubeconfig (optional)"}),e.jsx(E,{children:e.jsx(cs,{placeholder:"Paste NEW kubeconfig YAML to replace the stored one. Leave empty for no change.",rows:8,className:"font-mono",...i})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"md:col-span-2 gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>V(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:W.formState.isSubmitting,children:W.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ie,{open:!!x,onOpenChange:i=>!i&&c(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage node pools for ",e.jsx("span",{className:"font-mono",children:x?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached node pools"}),e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[(x?.node_pools||[]).map(i=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:i.name}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>me(x.id,i.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},i.id)),(x?.node_pools||[]).length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:2,className:"text-muted-foreground py-8 text-center",children:"No pools attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(X),className:"space-y-3",children:[e.jsx(v,{control:n.control,name:"node_pool_ids",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more node pools"}),e.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:[ge.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more node pools available to attach"}),ge.map(D=>{const ze=i.value?.includes(D.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:ze,onCheckedChange:Fe=>{const Se=new Set(i.value||[]);Fe===!0?Se.add(D.id):Se.delete(D.id),i.onChange(Array.from(Se))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:D.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ps(D.id,8)})]})]},D.id)})]}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:n.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),n.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})}),e.jsx(ie,{open:!!S,onOpenChange:i=>!i&&G(null),children:e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage bastion for ",e.jsx("span",{className:"font-mono",children:S?.name})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Current"}),e.jsx("div",{className:"rounded-xl border p-3 text-sm",children:S?.bastion_server?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:S.bastion_server.hostname}),e.jsx("div",{className:"text-muted-foreground",children:S.bastion_server.ip})]}):e.jsx("div",{className:"text-muted-foreground",children:"None"})})]}),e.jsx(ne,{...Re,children:e.jsxs("form",{onSubmit:Re.handleSubmit(Y),className:"space-y-4",children:[e.jsx(v,{control:Re.control,name:"server_id",render:({field:i})=>e.jsxs(b,{children:[e.jsx(N,{children:"New bastion server (UUID)"}),e.jsx(E,{children:e.jsx(z,{placeholder:"paste server UUID",...i})}),u.length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Suggestions:",e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:u.slice(0,8).map(D=>e.jsxs(h,{type:"button",size:"sm",variant:i.value===D.id?"default":"outline",onClick:()=>i.onChange(D.id),className:"font-normal",children:[e.jsx(hs,{className:"mr-1 h-3 w-3"})," ",D.hostname||ps(D.id,6)]},D.id))})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"secondary",onClick:()=>void he(),children:"Clear bastion"}),e.jsx(h,{type:"submit",disabled:Re.formState.isSubmitting,children:Re.formState.isSubmitting?"Saving…":"Set bastion"})]})]})})]})}),e.jsx("pre",{children:JSON.stringify(s,null,2)})]})}const Gr=re({key:F().trim().min(2,"Key is too short"),value:F().trim().min(2,"Value is too short")}),Jr=re({key:F().trim().min(2,"Key is too short").optional(),value:F().trim().min(2,"Value is too short").optional()}).refine(s=>s.key!==void 0||s.value!==void 0,{message:"Provide a new key or value",path:["key"]}),Qr=re({node_pool_ids:Oe(F().uuid()).min(1,"Pick at least one node pool")});function Wr(s,t=8){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}const Yr=()=>{const[s,t]=o.useState([]),[r,d]=o.useState([]),[u,f]=o.useState(!1),[$,C]=o.useState(null),[O,M]=o.useState(!1),[R,U]=o.useState(!1),[T,P]=o.useState(null),[j,V]=o.useState(null);async function H(){f(!0),C(null);try{const[a,n]=await Promise.all([g.get("/api/v1/labels?include=node_pools"),g.get("/api/v1/node-pools")]),_=(a||[]).map(X=>({id:X.id,key:X.key,value:X.value,node_pools:X.node_pools??X.node_groups??[]}));if(t(_),d(n||[]),j){const X=_.find(me=>me.id===j.id)||null;V(X)}if(T){const X=_.find(me=>me.id===T.id)||null;P(X)}}catch(a){console.error(a);const n=a instanceof je?a.message:"Failed to load labels/pools";C(n)}finally{f(!1)}}o.useEffect(()=>{H()},[]);const m=te({resolver:ae(Gr),defaultValues:{key:"",value:""}}),x=async a=>{await g.post("/api/v1/labels",{key:a.key.trim(),value:a.value.trim()}),M(!1),m.reset(),await H()},c=te({resolver:ae(Jr),defaultValues:{key:void 0,value:void 0}});function S(a){P(a),c.reset({key:void 0,value:void 0}),U(!0)}const G=async a=>{if(!T)return;const n={};a.key!==void 0&&(n.key=a.key.trim()),a.value!==void 0&&(n.value=a.value.trim()),await g.patch(`/api/v1/labels/${T.id}`,n),U(!1),P(null),await H()};async function K(a){confirm("Delete this label? This cannot be undone.")&&(await g.delete(`/api/v1/labels/${a}`),await H())}const B=te({resolver:ae(Qr),defaultValues:{node_pool_ids:[]}});function xe(a){V(a),B.reset({node_pool_ids:[]})}const W=async a=>{j&&(await g.post(`/api/v1/labels/${j.id}/node_pools`,{node_pool_ids:a.node_pool_ids}),B.reset({node_pool_ids:[]}),await H())};async function ue(a){j&&confirm("Detach this label from the selected node pool?")&&(await g.delete(`/api/v1/labels/${j.id}/node_pools/${a}`),await H())}const fe=o.useMemo(()=>{if(!j)return[];const a=new Set((j.node_pools||[]).map(n=>n.id));return r.filter(n=>!a.has(n.id))},[j,r]);return u?e.jsx("div",{className:"p-6",children:"Loading labels…"}):$?e.jsx("div",{className:"p-6 text-red-500",children:$}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Labels"}),e.jsxs(ie,{open:O,onOpenChange:M,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>M(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"}),"Create Label"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create Label"})}),e.jsx(ne,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(x),className:"space-y-4",children:[e.jsx(v,{control:m.control,name:"key",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key"}),e.jsx(E,{children:e.jsx(z,{placeholder:"app.kubernetes.io/managed-by",...a})}),e.jsx(w,{})]})}),e.jsx(v,{control:m.control,name:"value",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Value"}),e.jsx(E,{children:e.jsx(z,{placeholder:"GlueOps",...a})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:m.formState.isSubmitting,children:m.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Key"}),e.jsx(A,{children:"Value"}),e.jsx(A,{children:"Node Pools"}),e.jsx(A,{className:"w-[260px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[s.map(a=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:a.key}),e.jsx(p,{children:a.value}),e.jsx(p,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(a.node_pools||[]).slice(0,6).map(n=>e.jsx(Ce,{variant:"secondary",children:n.name},n.id)),(a.node_pools||[]).length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No pools"}),(a.node_pools||[]).length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",(a.node_pools||[]).length-6," more"]})]})}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>xe(a),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),"Manage node pools"]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>S(a),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"}),"Edit"]}),e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>K(a.id),children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"}),"Delete"]})]})})]},a.id)),s.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:4,className:"text-muted-foreground py-10 text-center",children:"No labels yet."})})]})]})})}),e.jsx(ie,{open:R,onOpenChange:a=>!a&&U(!1),children:e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Edit Label"," ",T?e.jsxs("span",{className:"text-muted-foreground ml-2 font-mono text-sm",children:["(",T.key," = ",T.value,")"]}):null]})}),e.jsx(ne,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(G),className:"space-y-4",children:[e.jsx(v,{control:c.control,name:"key",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"New key (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:T?.key||"e.g. app",...a})}),e.jsx(w,{})]})}),e.jsx(v,{control:c.control,name:"value",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"New value (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:T?.value||"e.g. GlueOps",...a})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>U(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:c.formState.isSubmitting,children:c.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ie,{open:!!j,onOpenChange:a=>!a&&V(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage node pools for"," ",e.jsx("span",{className:"font-mono",children:j?`${j.key}=${j.value}`:""})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached node pools"}),e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[(j?.node_pools||[]).map(a=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:a.name}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>ue(a.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},a.id)),(j?.node_pools||[]).length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:2,className:"text-muted-foreground py-8 text-center",children:"No pools attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...B,children:e.jsxs("form",{onSubmit:B.handleSubmit(W),className:"space-y-3",children:[e.jsx(v,{control:B.control,name:"node_pool_ids",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more node pools"}),e.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:[fe.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more node pools available to attach"}),fe.map(n=>{const _=a.value?.includes(n.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:_,onCheckedChange:X=>{const me=new Set(a.value||[]);X===!0?me.add(n.id):me.delete(n.id),a.onChange(Array.from(me))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:n.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:Wr(n.id,8)})]})]},n.id)})]}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:B.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),B.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})},Xr=re({name:F().trim().min(1,"Name is required").max(120,"Max 120 chars"),server_ids:Oe(F().uuid()).optional().default([])}),Zr=re({name:F().trim().min(1,"Name is required").max(120,"Max 120 chars")}),ei=re({server_ids:Oe(F().uuid()).min(1,"Pick at least one server")}),si=re({label_ids:Oe(F().uuid()).min(1,"Pick at least one label")}),ti=re({taint_ids:Oe(F().uuid()).min(1,"Pick at least one taint")}),ai=re({annotation_ids:Oe(F().uuid()).min(1,"Pick at least one annotation")});function pt({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Ce,{variant:t,className:"capitalize",children:s||"unknown"})}function ts(s,t=12){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}function gt(s){const t=s.ip||s.ip_address,r=s.hostname||t||s.id,d=s.role?` · ${s.role}`:"";return`${r}${d}`}function ni(s){return`${s.key}=${s.value}`}function vt(s){return`${s.value?`${s.key}=${s.value}`:s.key}:${s.effect}`}function bt(s){return`${s.name}=${s.value}`}const ri=()=>{const[s,t]=o.useState(!0),[r,d]=o.useState([]),[u,f]=o.useState([]),[$,C]=o.useState([]),[O,M]=o.useState([]),[R,U]=o.useState([]),[T,P]=o.useState(null),[j,V]=o.useState(""),[H,m]=o.useState(!1),[x,c]=o.useState(null),[S,G]=o.useState(null),[K,B]=o.useState(null),[xe,W]=o.useState([]),[ue,fe]=o.useState(!1),[a,n]=o.useState(null),[_,X]=o.useState(null),[me,ge]=o.useState([]),[Re,y]=o.useState(!1),[Y,he]=o.useState(null),[i,D]=o.useState(null),[ze,Fe]=o.useState([]),[Se,pe]=o.useState(!1),[He,dt]=o.useState(null);async function _e(){t(!0),P(null);try{const[l,k,Q,I,Z]=await Promise.all([g.get("/api/v1/node-pools?include=servers"),g.get("/api/v1/servers"),g.get("/api/v1/labels?include=node_pools"),g.get("/api/v1/taints?include=node_pools"),g.get("/api/v1/annotations?include=node_pools")]);if(d(l||[]),f(k||[]),C(Q||[]),M(I||[]),U(Z||[]),S){const ke=(l||[]).find(J=>J.id===S.id)||null;G(ke)}if(x){const ke=(l||[]).find(J=>J.id===x.id)||null;c(ke)}K&&await ks(K.id),_&&await As(_.id),i&&await Es(i.id)}catch(l){console.error(l);const k=l instanceof je?l.message:"Failed to load node pools / servers / labels / taints / annotations";P(k)}finally{t(!1)}}async function ks(l){fe(!0),n(null);try{const k=await g.get(`/api/v1/node-pools/${l}/labels`);W(k||[])}catch(k){console.error(k);const Q=k instanceof je?k.message:"Failed to load labels for pool";n(Q)}finally{fe(!1)}}async function As(l){y(!0),he(null);try{const k=await g.get(`/api/v1/node-pools/${l}/taints`);ge(k||[])}catch(k){console.error(k);const Q=k instanceof je?k.message:"Failed to load taints for pool";he(Q)}finally{y(!1)}}async function Es(l){pe(!0),dt(null);try{const k=await g.get(`/api/v1/node-pools/${l}/annotations`);Fe(k||[])}catch(k){console.error(k);const Q=k instanceof je?k.message:"Failed to load annotations for pool";dt(Q)}finally{pe(!1)}}o.useEffect(()=>{_e()},[]);const Fs=o.useMemo(()=>{const l=new Map;for(const k of $)for(const Q of k.node_groups||[]){const I=l.get(Q.id)||[];I.push({id:k.id,key:k.key,value:k.value}),l.set(Q.id,I)}return l},[$]),Rs=o.useMemo(()=>{const l=new Map;for(const k of O)for(const Q of k.node_groups||[]){const I=l.get(Q.id)||[];I.push({id:k.id,key:k.key,value:k.value,effect:k.effect}),l.set(Q.id,I)}return l},[O]),Vs=o.useMemo(()=>{const l=new Map;for(const k of R)for(const Q of k.node_pools||[]){const I=l.get(Q.id)||[];I.push({id:k.id,name:k.name,value:k.value}),l.set(Q.id,I)}return l},[R]),ct=o.useMemo(()=>{const l=j.trim().toLowerCase();return l?r.filter(k=>{const Q=(k.servers||[]).some(J=>(J.hostname||"").toLowerCase().includes(l)||(J.ip||J.ip_address||"").toLowerCase().includes(l)||(J.role||"").toLowerCase().includes(l)),I=(Fs.get(k.id)||[]).some(J=>J.key.toLowerCase().includes(l)||(J.value||"").toLowerCase().includes(l)),Z=(Rs.get(k.id)||[]).some(J=>{const ra=`${J.key}=${J.value}`.toLowerCase();return J.key.toLowerCase().includes(l)||(J.value||"").toLowerCase().includes(l)||J.effect.toLowerCase().includes(l)||ra.includes(l)}),ke=(Vs.get(k.id)||[]).some(J=>J.name.toLowerCase().includes(l)||(J.value||"").toLowerCase().includes(l)||`${J.name}=${J.value}`.toLowerCase().includes(l));return k.name.toLowerCase().includes(l)||Q||I||Z||ke}):r},[r,j,Fs,Rs,Vs]);async function Bt(l){confirm("Delete this node pool? This cannot be undone.")&&(await g.delete(`/api/v1/node-pools/${l}`),await _e())}const Ye=te({resolver:ae(Xr),defaultValues:{name:"",server_ids:[]}}),Ht=async l=>{const k={name:l.name.trim()};l.server_ids&&l.server_ids.length>0&&(k.server_ids=l.server_ids),await g.post("/api/v1/node-pools",k),m(!1),Ye.reset({name:"",server_ids:[]}),await _e()},ds=te({resolver:ae(Zr),defaultValues:{name:""}});function Kt(l){c(l),ds.reset({name:l.name})}const qt=async l=>{x&&(await g.patch(`/api/v1/node-pools/${x.id}`,{name:l.name.trim()}),c(null),await _e())},Xe=te({resolver:ae(ei),defaultValues:{server_ids:[]}});function Gt(l){G(l),Xe.reset({server_ids:[]})}const Jt=async l=>{S&&(await g.post(`/api/v1/node-pools/${S.id}/servers`,{server_ids:l.server_ids}),Xe.reset({server_ids:[]}),await _e())};async function Qt(l){S&&confirm("Detach this server from the pool?")&&(await g.delete(`/api/v1/node-pools/${S.id}/servers/${l}`),await _e())}const Ze=te({resolver:ae(si),defaultValues:{label_ids:[]}});function Wt(l){B(l),Ze.reset({label_ids:[]}),ks(l.id)}const Yt=async l=>{K&&(await g.post(`/api/v1/node-pools/${K.id}/labels`,{label_ids:l.label_ids}),Ze.reset({label_ids:[]}),await ks(K.id),await _e())};async function Xt(l){K&&confirm("Detach this label from the pool?")&&(await g.delete(`/api/v1/node-pools/${K.id}/labels/${l}`),await ks(K.id),await _e())}const es=te({resolver:ae(ti),defaultValues:{taint_ids:[]}});function Zt(l){X(l),es.reset({taint_ids:[]}),As(l.id)}const ea=async l=>{_&&(await g.post(`/api/v1/node-pools/${_.id}/taints`,{taint_ids:l.taint_ids}),es.reset({taint_ids:[]}),await As(_.id),await _e())};async function sa(l){_&&confirm("Detach this taint from the pool?")&&(await g.delete(`/api/v1/node-pools/${_.id}/taints/${l}`),await As(_.id),await _e())}const ss=te({resolver:ae(ai),defaultValues:{annotation_ids:[]}});function ta(l){D(l),ss.reset({annotation_ids:[]}),Es(l.id)}const aa=async l=>{i&&(await g.post(`/api/v1/node-pools/${i.id}/annotations`,{annotation_ids:l.annotation_ids}),ss.reset({annotation_ids:[]}),await Es(i.id),await _e())};async function na(l){i&&confirm("Detach this annotation from the pool?")&&(await g.delete(`/api/v1/node-pools/${i.id}/annotations/${l}`),await Es(i.id),await _e())}return s?e.jsx("div",{className:"p-6",children:"Loading node pools…"}):T?e.jsx("div",{className:"p-6 text-red-500",children:T}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Node Pools"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ts,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(z,{value:j,onChange:l=>V(l.target.value),placeholder:"Search pools, servers, labels, taints, annotations…",className:"w-72 pl-8"})]}),e.jsxs(h,{variant:"outline",onClick:_e,children:[e.jsx(Ps,{className:"mr-2 h-4 w-4"})," Refresh"]}),e.jsxs(ie,{open:H,onOpenChange:m,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>m(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"})," Create Pool"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create node pool"})}),e.jsx(ne,{...Ye,children:e.jsxs("form",{onSubmit:Ye.handleSubmit(Ht),className:"space-y-4",children:[e.jsx(v,{control:Ye.control,name:"name",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"pool-workers-a",...l})}),e.jsx(w,{})]})}),e.jsx(v,{control:Ye.control,name:"server_ids",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Initial servers (optional)"}),e.jsxs("div",{className:"max-h-56 space-y-2 overflow-auto rounded-xl border p-2",children:[u.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No servers available"}),u.map(k=>{const Q=l.value?.includes(k.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:Q,onCheckedChange:I=>{const Z=new Set(l.value||[]);I===!0?Z.add(k.id):Z.delete(k.id),l.onChange(Array.from(Z))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:gt(k)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ts(k.id,8)})]})]},k.id)})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:Ye.formState.isSubmitting,children:Ye.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{children:"Servers"}),e.jsx(A,{children:"Annotations"}),e.jsx(A,{children:"Labels"}),e.jsx(A,{children:"Taints"}),e.jsx(A,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[ct.map(l=>{const k=Fs.get(l.id)||[],Q=Rs.get(l.id)||[],I=Vs.get(l.id)||[];return e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:l.name}),e.jsxs(p,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(l.servers||[]).slice(0,6).map(Z=>e.jsxs(Ce,{variant:"secondary",className:"gap-1",children:[e.jsx(hs,{className:"h-3 w-3"})," ",Z.hostname||Z.ip||Z.ip_address||ts(Z.id,6),e.jsx("span",{className:"ml-1",children:Z.role}),Z.status&&e.jsx("span",{className:"ml-1",children:e.jsx(pt,{status:Z.status})})]},Z.id)),(l.servers||[]).length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No servers"}),(l.servers||[]).length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",(l.servers||[]).length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Gt(l),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage servers"]})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[I.slice(0,6).map(Z=>e.jsxs(Ce,{variant:"outline",className:"font-mono",children:[e.jsx($s,{className:"mr-1 h-3 w-3"}),bt(Z)]},Z.id)),I.length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No annotations"}),I.length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",I.length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>ta(l),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage Annotations"]})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[k.slice(0,6).map(Z=>e.jsxs(Ce,{variant:"outline",className:"font-mono",children:[e.jsx($s,{className:"mr-1 h-3 w-3"}),Z.key,"=",Z.value]},Z.id)),k.length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No labels"}),k.length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",k.length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Wt(l),children:[e.jsx($s,{className:"mr-2 h-4 w-4"})," Manage Labels"]})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[Q.slice(0,6).map(Z=>e.jsxs(Ce,{variant:"outline",className:"font-mono",children:[e.jsx($s,{className:"mr-1 h-3 w-3"}),vt(Z)]},Z.id)),Q.length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No taints"}),Q.length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",Q.length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Zt(l),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage Taints"]})]}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Kt(l),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(ls,{align:"end",children:e.jsx(Ie,{onClick:()=>Bt(l.id),children:"Confirm delete"})})]})]})})]},l.id)}),ct.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:6,className:"text-muted-foreground py-10 text-center",children:"No node pools match your search."})})]})]})})}),e.jsx(ie,{open:!!x,onOpenChange:l=>!l&&c(null),children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsx(le,{children:e.jsx(ce,{children:"Edit node pool"})}),e.jsx(ne,{...ds,children:e.jsxs("form",{onSubmit:ds.handleSubmit(qt),className:"space-y-4",children:[e.jsx(v,{control:ds.control,name:"name",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"pool-workers-a",...l})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>c(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:ds.formState.isSubmitting,children:ds.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ie,{open:!!S,onOpenChange:l=>!l&&G(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage servers for ",e.jsx("span",{className:"font-mono",children:S?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached servers"}),e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Server"}),e.jsx(A,{children:"IP"}),e.jsx(A,{children:"Role"}),e.jsx(A,{children:"Status"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[(S?.servers||[]).map(l=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:l.hostname||ts(l.id,8)}),e.jsx(p,{children:e.jsx("code",{className:"font-mono text-sm",children:l.ip||l.ip_address||"—"})}),e.jsx(p,{className:"capitalize",children:l.role||"—"}),e.jsx(p,{children:e.jsx(pt,{status:l.status})}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>Qt(l.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},l.id)),(S?.servers||[]).length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:5,className:"text-muted-foreground py-8 text-center",children:"No servers attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...Xe,children:e.jsxs("form",{onSubmit:Xe.handleSubmit(Jt),className:"space-y-3",children:[e.jsx(v,{control:Xe.control,name:"server_ids",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more servers"}),e.jsx("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:(()=>{const k=new Set((S?.servers||[]).map(I=>I.id)),Q=u.filter(I=>!k.has(I.id));return Q.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more servers available to attach"}):Q.map(I=>{const Z=l.value?.includes(I.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:Z,onCheckedChange:ke=>{const J=new Set(l.value||[]);ke===!0?J.add(I.id):J.delete(I.id),l.onChange(Array.from(J))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:gt(I)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ts(I.id,8)})]})]},I.id)})})()}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:Xe.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",Xe.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})}),e.jsx(ie,{open:!!K,onOpenChange:l=>!l&&B(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage labels for ",e.jsx("span",{className:"font-mono",children:K?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached labels"}),ue?e.jsx("div",{className:"text-muted-foreground rounded-md border p-3 text-sm",children:"Loading…"}):a?e.jsx("div",{className:"rounded-md border p-3 text-sm text-red-500",children:a}):e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Key"}),e.jsx(A,{children:"Value"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[xe.map(l=>e.jsxs(q,{children:[e.jsx(p,{className:"font-mono text-sm",children:l.key}),e.jsx(p,{className:"font-mono text-sm",children:l.value}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>Xt(l.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},l.id)),xe.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:3,className:"text-muted-foreground py-8 text-center",children:"No labels attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...Ze,children:e.jsxs("form",{onSubmit:Ze.handleSubmit(Yt),className:"space-y-3",children:[e.jsx(v,{control:Ze.control,name:"label_ids",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more labels"}),e.jsx("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:(()=>{const k=new Set(xe.map(I=>I.id)),Q=$.filter(I=>!k.has(I.id));return Q.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more labels available to attach"}):Q.map(I=>{const Z=l.value?.includes(I.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:Z,onCheckedChange:ke=>{const J=new Set(l.value||[]);ke===!0?J.add(I.id):J.delete(I.id),l.onChange(Array.from(J))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:ni(I)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ts(I.id,8)})]})]},I.id)})})()}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:Ze.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",Ze.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})}),e.jsx(ie,{open:!!_,onOpenChange:l=>!l&&X(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage taints for ",e.jsx("span",{className:"font-mono",children:_?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached taints"}),Re?e.jsx("div",{className:"text-muted-foreground rounded-md border p-3 text-sm",children:"Loading…"}):Y?e.jsx("div",{className:"rounded-md border p-3 text-sm text-red-500",children:Y}):e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Key"}),e.jsx(A,{children:"Value"}),e.jsx(A,{children:"Effect"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[me.map(l=>e.jsxs(q,{children:[e.jsx(p,{className:"font-mono text-sm",children:l.key}),e.jsx(p,{className:"font-mono text-sm",children:l.value}),e.jsx(p,{className:"font-mono text-sm",children:l.effect}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>sa(l.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},l.id)),me.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:4,className:"text-muted-foreground py-8 text-center",children:"No taints attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...es,children:e.jsxs("form",{onSubmit:es.handleSubmit(ea),className:"space-y-3",children:[e.jsx(v,{control:es.control,name:"taint_ids",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more taints"}),e.jsx("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:(()=>{const k=new Set(me.map(I=>I.id)),Q=O.filter(I=>!k.has(I.id));return Q.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more taints available to attach"}):Q.map(I=>{const Z=l.value?.includes(I.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:Z,onCheckedChange:ke=>{const J=new Set(l.value||[]);ke===!0?J.add(I.id):J.delete(I.id),l.onChange(Array.from(J))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:vt(I)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ts(I.id,8)})]})]},I.id)})})()}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:es.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",es.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})}),e.jsx(ie,{open:!!i,onOpenChange:l=>!l&&D(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage annotations for"," ",e.jsx("span",{className:"font-mono",children:i?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached annotations"}),Se?e.jsx("div",{className:"text-muted-foreground rounded-md border p-3 text-sm",children:"Loading…"}):He?e.jsx("div",{className:"rounded-md border p-3 text-sm text-red-500",children:He}):e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{children:"Value"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[ze.map(l=>e.jsxs(q,{children:[e.jsx(p,{className:"font-mono text-sm",children:l.name}),e.jsx(p,{className:"font-mono text-sm",children:l.value}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>na(l.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},l.id)),ze.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:3,className:"text-muted-foreground py-8 text-center",children:"No annotations attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...ss,children:e.jsxs("form",{onSubmit:ss.handleSubmit(aa),className:"space-y-3",children:[e.jsx(v,{control:ss.control,name:"annotation_ids",render:({field:l})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more annotations"}),e.jsx("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:(()=>{const k=new Set(ze.map(I=>I.id)),Q=R.filter(I=>!k.has(I.id));return Q.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more annotations available to attach"}):Q.map(I=>{const Z=l.value?.includes(I.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:Z,onCheckedChange:ke=>{const J=new Set(l.value||[]);ke===!0?J.add(I.id):J.delete(I.id),l.onChange(Array.from(J))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:bt(I)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:ts(I.id,8)})]})]},I.id)})})()}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:ss.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",ss.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})},gs=["pending","provisioning","ready","failed"],vs=["master","worker","bastion"],Ut=re({hostname:F().trim().max(120,"Max 120 chars").optional(),ip_address:F().trim().min(1,"IP address is required"),role:Je(vs),ssh_key_id:us("Pick a valid SSH key"),ssh_user:F().trim().min(1,"SSH user is required"),status:Je(gs).default("pending")}),ii=Ut.partial();function oi({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Ce,{variant:t,className:"capitalize",children:s})}function Bs(s,t=16){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}const li=()=>{const[s,t]=o.useState([]),[r,d]=o.useState([]),[u,f]=o.useState(!1),[$,C]=o.useState(null),[O,M]=o.useState(""),[R,U]=o.useState(""),[T,P]=o.useState(""),[j,V]=o.useState(!1),[H,m]=o.useState(null);function x(){const a=new URLSearchParams;return R&&a.set("status",R),T&&a.set("role",T),`/api/v1/servers${a.toString()?`?${a.toString()}`:""}`}async function c(){f(!0),C(null);try{const[a,n]=await Promise.all([g.get(x()),g.get("/api/v1/ssh")]);t(a??[]),d(n??[])}catch(a){console.error(a),C("Failed to load servers or SSH keys")}finally{f(!1)}}o.useEffect(()=>{c();const a=n=>{n.key==="active_org_id"&&c()};return window.addEventListener("storage",a),()=>window.removeEventListener("storage",a)},[]),o.useEffect(()=>{c()},[R,T]);const S=o.useMemo(()=>{const a=new Map;return r.forEach(n=>a.set(n.id,n)),a},[r]),G=o.useMemo(()=>{const a=O.trim().toLowerCase();return a?s.filter(n=>(n.hostname??"").toLowerCase().includes(a)||n.ip_address.toLowerCase().includes(a)||n.role.toLowerCase().includes(a)||n.ssh_user.toLowerCase().includes(a)):s},[s,O]);async function K(a){confirm("Delete this server? This cannot be undone.")&&(await g.delete(`/api/v1/servers/${encodeURIComponent(a)}`),await c())}const B=te({resolver:ae(Ut),defaultValues:{hostname:"",ip_address:"",role:"worker",ssh_key_id:"",ssh_user:"ubuntu",status:"pending"}}),xe=async a=>{const n={ip_address:a.ip_address.trim(),role:a.role,ssh_key_id:a.ssh_key_id,ssh_user:a.ssh_user.trim(),status:a.status};a.hostname&&a.hostname.trim()&&(n.hostname=a.hostname.trim()),await g.post("/api/v1/servers",n),V(!1),B.reset(),await c()},W=te({resolver:ae(ii),defaultValues:{}});function ue(a){m(a),W.reset({hostname:a.hostname??"",ip_address:a.ip_address,role:vs.includes(a.role)?a.role:"worker",ssh_key_id:a.ssh_key_id,ssh_user:a.ssh_user,status:gs.includes(a.status)?a.status:"pending"})}const fe=async a=>{if(!H)return;const n={};a.hostname!==void 0&&(n.hostname=a.hostname?.trim()||""),a.ip_address!==void 0&&(n.ip_address=a.ip_address.trim()),a.role!==void 0&&(n.role=a.role),a.ssh_key_id!==void 0&&(n.ssh_key_id=a.ssh_key_id),a.ssh_user!==void 0&&(n.ssh_user=a.ssh_user.trim()),a.status!==void 0&&(n.status=a.status),await g.patch(`/api/v1/servers/${encodeURIComponent(H.id)}`,n),m(null),await c()};return u?e.jsx("div",{className:"p-6",children:"Loading servers…"}):$?e.jsx("div",{className:"p-6 text-red-500",children:$}):e.jsxs(Os,{children:[e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Servers"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ts,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(z,{value:O,onChange:a=>M(a.target.value),placeholder:"Search hostname, IP, role, user…",className:"w-64 pl-8"})]}),e.jsxs(Ae,{value:T,onValueChange:a=>P(a),children:[e.jsx($e,{className:"w-36",children:e.jsx(Ee,{placeholder:"Role (all)"})}),e.jsx(Le,{children:vs.map(a=>e.jsx(ve,{value:a,children:a},a))})]}),e.jsxs(Ae,{value:R,onValueChange:a=>U(a),children:[e.jsx($e,{className:"w-40",children:e.jsx(Ee,{placeholder:"Status (all)"})}),e.jsx(Le,{children:gs.map(a=>e.jsx(ve,{value:a,children:a},a))})]}),e.jsxs(h,{variant:"outline",onClick:c,children:[e.jsx(Ps,{className:"mr-2 h-4 w-4"}),"Refresh"]}),e.jsxs(ie,{open:j,onOpenChange:V,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>V(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"}),"Create Server"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create server"})}),e.jsx(ne,{...B,children:e.jsxs("form",{onSubmit:B.handleSubmit(xe),className:"space-y-4",children:[e.jsx(v,{control:B.control,name:"hostname",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Hostname"}),e.jsx(E,{children:e.jsx(z,{placeholder:"worker-01",...a})}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"ip_address",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"IP address"}),e.jsx(E,{children:e.jsx(z,{placeholder:"10.0.1.23",...a})}),e.jsx(w,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(v,{control:B.control,name:"role",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"Select role"})})}),e.jsx(Le,{children:vs.map(n=>e.jsx(ve,{value:n,children:n},n))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"ssh_user",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"SSH user"}),e.jsx(E,{children:e.jsx(z,{placeholder:"ubuntu",...a})}),e.jsx(w,{})]})})]}),e.jsx(v,{control:B.control,name:"ssh_key_id",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"SSH key"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:r.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(Le,{children:r.map(n=>e.jsxs(ve,{value:n.id,children:[n.name?n.name:"Unnamed key"," —"," ",Bs(n.fingerprint,8)]},n.id))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:B.control,name:"status",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Initial status"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"pending"})})}),e.jsx(Le,{children:gs.map(n=>e.jsx(ve,{value:n,children:n},n))})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>V(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:B.formState.isSubmitting,children:B.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Hostname"}),e.jsx(A,{children:"IP address"}),e.jsx(A,{children:"Role"}),e.jsx(A,{children:"SSH user"}),e.jsx(A,{children:"SSH key"}),e.jsx(A,{children:"Status"}),e.jsx(A,{children:"Created"}),e.jsx(A,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[G.map(a=>{const n=S.get(a.ssh_key_id);return e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:a.hostname||"—"}),e.jsx(p,{children:e.jsx("code",{className:"font-mono text-sm",children:a.ip_address})}),e.jsx(p,{className:"capitalize",children:a.role}),e.jsx(p,{children:e.jsx("code",{className:"font-mono text-sm",children:a.ssh_user})}),e.jsx(p,{children:n?e.jsxs(Ys,{children:[e.jsx(Xs,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ce,{variant:"secondary",children:n.name||"SSH key"}),e.jsx("code",{className:"font-mono text-xs",children:Bs(n.fingerprint,8)})]})}),e.jsx(Zs,{className:"max-w-[70vw]",children:e.jsx("p",{className:"font-mono text-xs break-all",children:n.public_keys})})]}):e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})}),e.jsx(p,{children:e.jsx(oi,{status:a.status})}),e.jsx(p,{children:new Date(a.created_at).toLocaleString()}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>ue(a),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(ls,{align:"end",children:e.jsx(Ie,{onClick:()=>K(a.id),children:"Confirm delete"})})]})]})})]},a.id)}),G.length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:8,className:"text-muted-foreground py-10 text-center",children:"No servers match your filters."})})]})]})})})]}),e.jsx(ie,{open:!!H,onOpenChange:a=>!a&&m(null),children:e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Edit server"})}),e.jsx(ne,{...W,children:e.jsxs("form",{onSubmit:W.handleSubmit(fe),className:"space-y-4",children:[e.jsx(v,{control:W.control,name:"hostname",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Hostname"}),e.jsx(E,{children:e.jsx(z,{placeholder:"worker-01",...a})}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"ip_address",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"IP address"}),e.jsx(E,{children:e.jsx(z,{placeholder:"10.0.1.23",...a})}),e.jsx(w,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(v,{control:W.control,name:"role",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"Select role"})})}),e.jsx(Le,{children:vs.map(n=>e.jsx(ve,{value:n,children:n},n))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"ssh_user",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"SSH user"}),e.jsx(E,{children:e.jsx(z,{placeholder:"ubuntu",...a})}),e.jsx(w,{})]})})]}),e.jsx(v,{control:W.control,name:"ssh_key_id",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"SSH key"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:r.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(Le,{children:r.map(n=>e.jsxs(ve,{value:n.id,children:[n.name?n.name:"SSH key"," — ",Bs(n.fingerprint,8)]},n.id))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:W.control,name:"status",render:({field:a})=>e.jsxs(b,{children:[e.jsx(N,{children:"Status"}),e.jsxs(Ae,{onValueChange:a.onChange,value:a.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"pending"})})}),e.jsx(Le,{children:gs.map(n=>e.jsx(ve,{value:n,children:n},n))})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>m(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:W.formState.isSubmitting,children:W.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})},Is=["NoSchedule","PreferNoSchedule","NoExecute"],di=re({key:F().trim().min(1,"Key is required").max(120,"Max 120 chars"),value:F().trim().optional(),effect:Je(Is),node_pool_ids:Oe(us()).optional().default([])}),ci=re({key:F().trim().min(1,"Key is required").max(120).optional(),value:F().trim().optional(),effect:Je(Is).optional()}),mi=re({node_pool_ids:Oe(F().uuid()).min(1,"Pick at least one node pool")});function Hs(s,t=12){return s?s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`:""}function xi({t:s}){const t=`${s.key}${s.value?`=${s.value}`:""}${s.effect?`:${s.effect}`:""}`;return e.jsxs(Ce,{variant:"secondary",className:"font-mono text-xs",children:[e.jsx(It,{className:"mr-1 h-3 w-3"}),t]})}const hi=()=>{const[s,t]=o.useState(!0),[r,d]=o.useState(null),[u,f]=o.useState([]),[$,C]=o.useState([]),[O,M]=o.useState(""),[R,U]=o.useState(!1),[T,P]=o.useState(null),[j,V]=o.useState(null);async function H(){t(!0),d(null);try{const[n,_]=await Promise.all([g.get("/api/v1/taints?include=node_groups"),g.get("/api/v1/node-pools")]);if(f(n||[]),C(_||[]),j){const X=(n||[]).find(me=>me.id===j.id)||null;V(X)}if(T){const X=(n||[]).find(me=>me.id===T.id)||null;P(X)}}catch(n){console.error(n);const _=n instanceof je?n.message:"Failed to load taints or node pools";d(_)}finally{t(!1)}}o.useEffect(()=>{H()},[]);const m=o.useMemo(()=>{const n=O.trim().toLowerCase();return n?u.filter(_=>{const X=`${_.key}${_.value?`=${_.value}`:""}${_.effect?`:${_.effect}`:""}`.toLowerCase(),me=(_.node_groups||[]).some(ge=>ge.name.toLowerCase().includes(n));return X.includes(n)||me}):u},[u,O]);async function x(n){confirm("Delete this taint? This cannot be undone.")&&(await g.delete(`/api/v1/taints/${n}`),await H())}const c=te({resolver:ae(di),defaultValues:{key:"",value:"",effect:void 0,node_pool_ids:[]}}),S=async n=>{const _={key:n.key.trim(),effect:n.effect};n.value&&(_.value=n.value.trim()),n.node_pool_ids&&n.node_pool_ids.length>0&&(_.node_pool_ids=n.node_pool_ids),await g.post("/api/v1/taints",_),U(!1),c.reset({key:"",value:"",effect:void 0,node_pool_ids:[]}),await H()},G=te({resolver:ae(ci),defaultValues:{}});function K(n){P(n),G.reset({key:n.key,value:n.value||"",effect:n.effect||void 0})}const B=async n=>{if(!T)return;const _={};n.key!==void 0&&(_.key=n.key.trim()),n.value!==void 0&&(_.value=n.value?.trim()??""),n.effect!==void 0&&(_.effect=n.effect),await g.patch(`/api/v1/taints/${T.id}`,_),P(null),await H()},xe=te({resolver:ae(mi),defaultValues:{node_pool_ids:[]}});function W(n){V(n),xe.reset({node_pool_ids:[]})}const ue=async n=>{j&&(await g.post(`/api/v1/taints/${j.id}/node_pools`,{node_pool_ids:n.node_pool_ids}),xe.reset({node_pool_ids:[]}),await H())};async function fe(n){j&&confirm("Detach this taint from the node pool?")&&(await g.delete(`/api/v1/taints/${j.id}/node_pools/${n}`),await H())}const a=o.useMemo(()=>{if(!j)return[];const n=new Set((j.node_groups||[]).map(_=>_.id));return $.filter(_=>!n.has(_.id))},[j,$]);return s?e.jsx("div",{className:"p-6",children:"Loading taints…"}):r?e.jsx("div",{className:"p-6 text-red-500",children:r}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Taints"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ts,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(z,{value:O,onChange:n=>M(n.target.value),placeholder:"Search taints or attached pools…",className:"w-72 pl-8"})]}),e.jsxs(h,{variant:"outline",onClick:H,children:[e.jsx(Ps,{className:"mr-2 h-4 w-4"})," Refresh"]}),e.jsxs(ie,{open:R,onOpenChange:U,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>U(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"})," Create Taint"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create taint"})}),e.jsx(ne,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(S),className:"space-y-4",children:[e.jsx(v,{control:c.control,name:"key",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key"}),e.jsx(E,{children:e.jsx(z,{placeholder:"dedicated",...n})}),e.jsx(w,{})]})}),e.jsx(v,{control:c.control,name:"value",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Value (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:"gpu",...n})}),e.jsx(w,{})]})}),e.jsx(v,{control:c.control,name:"effect",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Effect"}),e.jsxs(Ae,{onValueChange:n.onChange,value:n.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"Select effect"})})}),e.jsx(Le,{children:Is.map(_=>e.jsx(ve,{value:_,children:_},_))})]}),e.jsx(w,{})]})}),e.jsx(v,{control:c.control,name:"node_pool_ids",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach to node pools (optional)"}),e.jsxs("div",{className:"max-h-56 space-y-2 overflow-auto rounded-xl border p-2",children:[$.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No node pools available"}),$.map(_=>{const X=n.value?.includes(_.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:X,onCheckedChange:me=>{const ge=new Set(n.value||[]);me===!0?ge.add(_.id):ge.delete(_.id),n.onChange(Array.from(ge))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:_.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:Hs(_.id,8)})]})]},_.id)})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>U(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:c.formState.isSubmitting,children:c.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Taint"}),e.jsx(A,{children:"Attached Node Pools"}),e.jsx(A,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs(we,{children:[m.map(n=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xi,{t:n}),e.jsx("code",{className:"text-muted-foreground text-xs",children:Hs(n.id,6)})]})}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[(n.node_groups||[]).slice(0,6).map(_=>e.jsxs(Ce,{variant:"outline",className:"gap-1",children:[e.jsx(yn,{className:"h-3 w-3"}),_.name]},_.id)),(n.node_groups||[]).length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No node pools"}),(n.node_groups||[]).length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",(n.node_groups||[]).length-6," more"]})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>W(n),children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Manage node pools"]})]}),e.jsx(p,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>K(n),children:[e.jsx(rs,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(ls,{align:"end",children:e.jsx(Ie,{onClick:()=>x(n.id),children:"Confirm delete"})})]})]})})]},n.id)),m.length===0&&e.jsx(q,{children:e.jsxs(p,{colSpan:3,className:"text-muted-foreground py-10 text-center",children:[e.jsx(Sn,{className:"mx-auto mb-2 h-6 w-6 opacity-60"}),"No taints match your search."]})})]})]})})}),e.jsx(ie,{open:!!T,onOpenChange:n=>!n&&P(null),children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsx(le,{children:e.jsx(ce,{children:"Edit taint"})}),e.jsx(ne,{...G,children:e.jsxs("form",{onSubmit:G.handleSubmit(B),className:"space-y-4",children:[e.jsx(v,{control:G.control,name:"key",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key"}),e.jsx(E,{children:e.jsx(z,{placeholder:"dedicated",...n})}),e.jsx(w,{})]})}),e.jsx(v,{control:G.control,name:"value",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Value (optional)"}),e.jsx(E,{children:e.jsx(z,{placeholder:"gpu",...n})}),e.jsx(w,{})]})}),e.jsx(v,{control:G.control,name:"effect",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Effect"}),e.jsxs(Ae,{onValueChange:n.onChange,value:n.value,children:[e.jsx(E,{children:e.jsx($e,{children:e.jsx(Ee,{placeholder:"Select effect"})})}),e.jsx(Le,{children:Is.map(_=>e.jsx(ve,{value:_,children:_},_))})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>P(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:G.formState.isSubmitting,children:G.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ie,{open:!!j,onOpenChange:n=>!n&&V(null),children:e.jsxs(oe,{className:"sm:max-w-2xl",children:[e.jsx(le,{children:e.jsxs(ce,{children:["Manage pools for"," ",e.jsx("span",{className:"font-mono",children:j?`${j.key}${j.value?`=${j.value}`:""}${j.effect?`:${j.effect}`:""}`:""})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached node pools"}),e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs(we,{children:[(j?.node_groups||[]).map(n=>e.jsxs(q,{children:[e.jsx(p,{className:"font-medium",children:n.name}),e.jsx(p,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>fe(n.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},n.id)),(j?.node_groups||[]).length===0&&e.jsx(q,{children:e.jsx(p,{colSpan:2,className:"text-muted-foreground py-8 text-center",children:"No node pools attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(ne,{...xe,children:e.jsxs("form",{onSubmit:xe.handleSubmit(ue),className:"space-y-3",children:[e.jsx(v,{control:xe.control,name:"node_pool_ids",render:({field:n})=>e.jsxs(b,{children:[e.jsx(N,{children:"Attach more node pools"}),e.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto rounded-xl border p-2 md:grid-cols-2",children:[a.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more node pools available to attach"}),a.map(_=>{const X=n.value?.includes(_.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(De,{checked:X,onCheckedChange:me=>{const ge=new Set(n.value||[]);me===!0?ge.add(_.id):ge.delete(_.id),n.onChange(Array.from(ge))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:_.name}),e.jsx("div",{className:"text-muted-foreground text-xs",children:Hs(_.id,8)})]})]},_.id)})]}),e.jsx(w,{})]})}),e.jsx(de,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:xe.formState.isSubmitting,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," ",xe.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})};function Nt(){return e.jsxs("div",{className:"p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"403 — Forbidden"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"You don’t have access to this area."})]})}const wt=()=>{const s=_s();return e.jsxs("div",{className:"bg-background text-foreground flex min-h-screen flex-col items-center justify-center",children:[e.jsx("h1",{className:"mb-4 text-6xl font-bold",children:"404"}),e.jsx("p",{className:"mb-8 text-2xl",children:"Oops! Page not found"}),e.jsx(h,{onClick:()=>s("/dashboard"),children:"Go back to Dashboard"})]})},ui=re({name:F().min(1,"Name is required").max(100,"Max 100 characters"),comment:F().trim().max(100,"Max 100 characters").default(""),bits:Je(["2048","3072","4096"])});function ji(s,t="download.bin"){if(!s)return t;const r=/filename\*=UTF-8''([^;]+)/i.exec(s);return r?.[1]?decodeURIComponent(r[1]):/filename="?([^"]+)"?/i.exec(s)?.[1]??t}function fi(s,t=24){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}function pi(s){return s?.split(/\s+/)?.[0]??"ssh-key"}async function gi(s){try{await navigator.clipboard.writeText(s)}catch{const t=document.createElement("textarea");t.value=s,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}}const vi=()=>{const[s,t]=o.useState([]),[r,d]=o.useState(null),[u,f]=o.useState(!0),[$,C]=o.useState(""),[O,M]=o.useState(!1),R=o.useMemo(()=>!!localStorage.getItem("active_org_id"),[]);async function U(){f(!0),d(null);try{if(!R){t([]),d("Select an organization first.");return}const m=await g.get("/api/v1/ssh");t(m??[])}catch(m){console.error(m),d("Failed to fetch SSH keys")}finally{f(!1)}}o.useEffect(()=>{U();const m=x=>{x.key==="active_org_id"&&U()};return window.addEventListener("storage",m),()=>window.removeEventListener("storage",m)},[]);const T=s.filter(m=>`${m.name} ${m.public_keys} ${m.fingerprint}`.toLowerCase().includes($.toLowerCase()));async function P(m,x="both"){const c=localStorage.getItem("access_token"),S=localStorage.getItem("active_org_id"),G=`${Ls}/api/v1/ssh/${encodeURIComponent(m)}/download?part=${encodeURIComponent(x)}`;try{const K=await fetch(G,{method:"GET",headers:{...c?{Authorization:`Bearer ${c}`}:{},...S?{"X-Org-ID":S}:{}}});if(!K.ok){const a=await K.text().catch(()=>"");throw new Error(a||`HTTP ${K.status}`)}const B=await K.blob(),xe=x==="both"?`ssh_key_${m}.zip`:x==="public"?`id_rsa_${m}.pub`:`id_rsa_${m}.pem`,W=ji(K.headers.get("content-disposition")??void 0,xe),ue=URL.createObjectURL(B),fe=document.createElement("a");fe.href=ue,fe.download=W,document.body.appendChild(fe),fe.click(),fe.remove(),URL.revokeObjectURL(ue)}catch(K){console.error(K),alert(K instanceof Error?K.message:"Download failed")}}async function j(m){try{await g.delete(`/api/v1/ssh/${encodeURIComponent(m)}`),await U()}catch(x){console.error(x),alert("Failed to delete key")}}const V=te({resolver:ae(ui),defaultValues:{name:"",comment:"deploy@autoglue",bits:"4096"}});async function H(m){try{await g.post("/api/v1/ssh",{bits:Number(m.bits),comment:m.comment?.trim()??"",name:m.name.trim(),download:"none"}),M(!1),V.reset(),await U()}catch(x){console.error(x),alert("Failed to create key")}}return u?e.jsx("div",{className:"p-6",children:"Loading SSH Keys…"}):r?e.jsx("div",{className:"p-6 text-red-500",children:r}):e.jsx(Os,{children:e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"SSH Keys"}),e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(z,{value:$,onChange:m=>C(m.target.value),placeholder:"Search by name, fingerprint or key"})}),e.jsxs(ie,{open:O,onOpenChange:M,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>M(!0),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"}),"Create New Keypair"]})}),e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsx(le,{children:e.jsx(ce,{children:"Create SSH Keypair"})}),e.jsx(ne,{...V,children:e.jsxs("form",{onSubmit:V.handleSubmit(H),className:"space-y-4",children:[e.jsx(v,{control:V.control,name:"name",render:({field:m})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"e.g., CI deploy key",...m})}),e.jsx(w,{})]})}),e.jsx(v,{control:V.control,name:"comment",render:({field:m})=>e.jsxs(b,{children:[e.jsx(N,{children:"Comment"}),e.jsx(E,{children:e.jsx(z,{placeholder:"e.g., deploy@autoglue",...m})}),e.jsx(w,{})]})}),e.jsx(v,{control:V.control,name:"bits",render:({field:m})=>e.jsxs(b,{children:[e.jsx(N,{children:"Key size"}),e.jsx(E,{children:e.jsxs("select",{className:"bg-background w-full rounded-md border px-3 py-2 text-sm",value:m.value,onChange:m.onChange,children:[e.jsx("option",{value:"2048",children:"2048"}),e.jsx("option",{value:"3072",children:"3072"}),e.jsx("option",{value:"4096",children:"4096"})]})}),e.jsx(w,{})]})}),e.jsxs(de,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:V.formState.isSubmitting,children:V.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]}),e.jsx("div",{className:"bg-background overflow-hidden rounded-2xl border shadow-sm",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Name"}),e.jsx(A,{className:"min-w-[360px]",children:"Public Key"}),e.jsx(A,{children:"Fingerprint"}),e.jsx(A,{children:"Created"}),e.jsx(A,{className:"w-[160px] text-right",children:"Actions"})]})}),e.jsx(we,{children:T.map(m=>{const x=pi(m.public_keys),c=fi(m.public_keys,18);return e.jsxs(q,{children:[e.jsx(p,{className:"align-top",children:m.name}),e.jsx(p,{className:"align-top",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ce,{variant:"secondary",className:"whitespace-nowrap",children:x}),e.jsxs(Ys,{children:[e.jsx(Xs,{asChild:!0,children:e.jsx("code",{className:"font-mono text-sm break-all md:max-w-[48ch] md:truncate md:break-normal",children:c})}),e.jsx(Zs,{className:"max-w-[70vw]",children:e.jsx("div",{className:"max-w-full",children:e.jsx("p",{className:"font-mono text-xs break-all",children:m.public_keys})})})]})]})}),e.jsx(p,{className:"align-top",children:e.jsx("code",{className:"font-mono text-sm",children:m.fingerprint})}),e.jsx(p,{className:"align-top",children:new Date(m.created_at).toLocaleString(void 0,{year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),e.jsx(p,{className:"align-top",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>gi(m.public_keys),title:"Copy public key",children:[e.jsx(Cn,{className:"mr-2 h-4 w-4"}),"Copy"]}),e.jsxs(is,{children:[e.jsx(os,{asChild:!0,children:e.jsxs(h,{variant:"outline",size:"sm",children:[e.jsx(_n,{className:"mr-2 h-4 w-4"}),"Download"]})}),e.jsxs(ls,{align:"end",children:[e.jsx(Ie,{onClick:()=>P(m.id,"both"),children:"Public + Private (.zip)"}),e.jsx(Ie,{onClick:()=>P(m.id,"public"),children:"Public only (.pub)"}),e.jsx(Ie,{onClick:()=>P(m.id,"private"),children:"Private only (.pem)"})]})]}),e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>j(m.id),children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"}),"Delete"]})]})})]},m.id)})})]})})})]})})};function bi(s){const t=s?.user_id??s?.UserID??s?.user?.id??s?.User?.ID??"",r=s?.email??s?.Email??s?.user?.email??s?.User?.Email,d=s?.name??s?.Name??s?.user?.name??s?.User?.Name,u=s?.role??s?.Role??"member",f=s?.created_at??s?.CreatedAt;return{userId:String(t),email:r,name:d,role:String(u),joinedAt:f}}const Ni=re({email:js("Enter a valid email"),role:Je(["member","admin"])}),wi=()=>{const[s,t]=o.useState(!0),[r,d]=o.useState([]),[u,f]=o.useState(null),[$,C]=o.useState(!1),[O,M]=o.useState(!1),[R,U]=o.useState(null),T=o.useMemo(()=>Ke(),[]),P=te({resolver:ae(Ni),defaultValues:{email:"",role:"member"},mode:"onChange"});async function j(){try{const x=await g.get("/api/v1/auth/me");f(x)}catch{}}async function V(x){if(!x){d([]),t(!1);return}t(!0);try{const c=await g.get("/api/v1/orgs/members");d((c??[]).map(bi))}catch(c){const S=c instanceof je?c.message:"Failed to load members";ee.error(S)}finally{t(!1)}}o.useEffect(()=>{j(),V(T)},[T]),o.useEffect(()=>{const x=()=>void V(Ke()),c=S=>{S.key==="active_org_id"&&x()};return window.addEventListener(ns,x),window.addEventListener("storage",c),()=>{window.removeEventListener(ns,x),window.removeEventListener("storage",c)}},[]);async function H(x){const c=Ke();if(!c){ee.error("Select an organization first");return}try{M(!0),await g.post("/api/v1/orgs/invite",x),ee.success(`Invited ${x.email}`),C(!1),P.reset({email:"",role:"member"}),V(c)}catch(S){const G=S instanceof je?S.message:"Failed to invite member";ee.error(G)}finally{M(!1)}}async function m(x){const c=Ke();if(!c){ee.error("Select an organization first");return}try{U(x),await g.delete(`/api/v1/orgs/members/${x}`,{headers:{"X-Org-ID":c}}),d(S=>S.filter(G=>G.userId!==x)),ee.success("Member removed")}catch(S){const G=S instanceof je?S.message:"Failed to remove member";ee.error(G)}finally{U(null)}}return s?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Members"}),e.jsxs(h,{disabled:!0,children:[e.jsx(xt,{className:"mr-2 h-4 w-4"}),"Invite"]})]}),e.jsx(Ns,{}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((x,c)=>e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Ge,{className:"h-5 w-40"})}),e.jsxs(Me,{className:"space-y-2",children:[e.jsx(Ge,{className:"h-4 w-56"}),e.jsx(Ge,{className:"h-4 w-40"})]}),e.jsx(Ss,{children:e.jsx(Ge,{className:"h-9 w-24"})})]},c))})]}):Ke()?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Members"}),e.jsxs(ie,{open:$,onOpenChange:C,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{children:[e.jsx(xt,{className:"mr-2 h-4 w-4"}),"Invite"]})}),e.jsxs(oe,{className:"sm:max-w-[520px]",children:[e.jsxs(le,{children:[e.jsx(ce,{children:"Invite member"}),e.jsx(Ds,{children:"Send an invite to join this organization."})]}),e.jsx(ne,{...P,children:e.jsxs("form",{onSubmit:P.handleSubmit(H),className:"grid gap-4 py-2",children:[e.jsx(v,{control:P.control,name:"email",render:({field:x})=>e.jsxs(b,{children:[e.jsx(N,{children:"Email"}),e.jsx(E,{children:e.jsx(z,{type:"email",placeholder:"jane@example.com",...x})}),e.jsx(w,{})]})}),e.jsx(v,{control:P.control,name:"role",render:({field:x})=>e.jsxs(b,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Ae,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(E,{children:e.jsx($e,{className:"w-[200px]",children:e.jsx(Ee,{placeholder:"Select role"})})}),e.jsxs(Le,{children:[e.jsx(ve,{value:"member",children:"Member"}),e.jsx(ve,{value:"admin",children:"Admin"})]})]}),e.jsx(w,{})]})}),e.jsxs(de,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>C(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!P.formState.isValid||O,children:O?"Sending…":"Send invite"})]})]})})]})]})]}),e.jsx(Ns,{}),r.length===0?e.jsx("div",{className:"text-muted-foreground text-sm",children:"No members yet."}):e.jsx("div",{className:"grid grid-cols-1 gap-4 pr-2 sm:grid-cols-2 lg:grid-cols-3",children:r.map(x=>{const c=u?.id&&x.userId===u.id;return e.jsxs(Te,{className:"flex flex-col",children:[e.jsx(Pe,{children:e.jsx(Be,{className:"text-base",children:x.name||x.email||x.userId})}),e.jsxs(Me,{className:"text-muted-foreground space-y-1 text-sm",children:[x.email&&e.jsxs("div",{children:["Email: ",x.email]}),e.jsxs("div",{children:["Role: ",x.role]}),x.joinedAt&&e.jsxs("div",{children:["Joined: ",new Date(x.joinedAt).toLocaleString()]})]}),e.jsxs(Ss,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{}),e.jsxs(et,{children:[e.jsx(st,{asChild:!0,children:e.jsxs(h,{variant:"destructive",disabled:c||R===x.userId,className:"ml-auto",children:[e.jsx(Ue,{className:"mr-2 h-5 w-5"}),R===x.userId?"Removing…":"Remove"]})}),e.jsxs(tt,{children:[e.jsxs(at,{children:[e.jsx(rt,{children:"Remove member?"}),e.jsxs(it,{children:["This will remove ",e.jsx("b",{children:x.name||x.email||x.userId})," from the organization."]})]}),e.jsxs(nt,{className:"sm:justify-between",children:[e.jsx(lt,{disabled:R===x.userId,children:"Cancel"}),e.jsx(ot,{asChild:!0,disabled:R===x.userId,children:e.jsx(h,{variant:"destructive",onClick:()=>m(x.userId),children:"Confirm remove"})})]})]})]})]})]},x.userId)})})]}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h1",{className:"text-2xl font-bold",children:"Members"})}),e.jsx(Ns,{}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"No organization selected. Choose an organization to manage its members."})]})},yi=re({name:F().min(2).max(100),slug:F().min(2).max(50).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Use lowercase letters, numbers, and hyphens.")}),Si=()=>{const[s,t]=o.useState([]),[r,d]=o.useState(!0),[u,f]=o.useState(!1),[$,C]=o.useState(null),[O,M]=o.useState(null),R=o.useRef(!1),U=te({resolver:ae(yi),mode:"onChange",defaultValues:{name:"",slug:""}}),T=U.watch("name");o.useEffect(()=>{R.current||U.setValue("slug",ht(T||""),{shouldValidate:!0})},[T,U]);const P=async()=>{d(!0);try{const m=await g.get("/api/v1/orgs");t(m),f(m.length===0)}catch(m){const x=m instanceof je?m.message:"Failed to load organizations";ee.error(x)}finally{d(!1)}};o.useEffect(()=>{C(Ke()),P();const m=S=>{S.key==="active_org_id"&&C(S.newValue)};window.addEventListener("storage",m);const x=S=>{const G=S.detail??null;C(G)};window.addEventListener(ns,x);const c=()=>void P();return window.addEventListener(ys,c),()=>{window.removeEventListener("storage",m),window.removeEventListener(ns,x),window.removeEventListener(ys,c)}},[]);async function j(m){try{const x=await g.post("/api/v1/orgs",m);t(c=>[x,...c]),ws(x.id),C(x.id),ut(),ee.success(`Created ${x.name}`),f(!1),U.reset({name:"",slug:""}),R.current=!1}catch(x){const c=x instanceof je?x.message:"Failed to create organization";ee.error(c)}}function V(m){ws(m.id),C(m.id),ee.success(`Switched to ${m.name}`)}async function H(m){try{M(m.id),await g.delete(`/api/v1/orgs/${m.id}`),t(x=>{const c=x.filter(S=>S.id!==m.id);if($===m.id){const S=c[0]?.id??null;ws(S),C(S)}return c}),ut(),ee.success(`Deleted ${m.name}`)}catch(x){const c=x instanceof je?x.message:"Failed to delete organization";ee.error(c)}finally{M(null)}}return r?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Organizations"})}),e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((m,x)=>e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Ge,{className:"h-5 w-40"})}),e.jsxs(Me,{children:[e.jsx(Ge,{className:"mb-2 h-4 w-24"}),e.jsx(Ge,{className:"h-4 w-48"})]}),e.jsx(Ss,{children:e.jsx(Ge,{className:"h-9 w-24"})})]},x))})]}):e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:"Organizations"}),e.jsx(h,{onClick:()=>f(!0),children:"New organization"})]}),e.jsx(Ns,{}),s.length===0?e.jsx("div",{className:"text-muted-foreground text-sm",children:"No organizations yet."}):e.jsx("div",{className:"grid grid-cols-1 gap-4 pr-2 sm:grid-cols-2 lg:grid-cols-3",children:s.map(m=>e.jsxs(Te,{className:"flex flex-col",children:[e.jsx(Pe,{children:e.jsx(Be,{className:"text-base",children:m.name})}),e.jsxs(Me,{className:"text-muted-foreground text-sm",children:[e.jsxs("div",{children:["Slug: ",m.slug]}),e.jsxs("div",{className:"mt-1",children:["ID: ",m.id]})]}),e.jsxs(Ss,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{onClick:()=>V(m),children:m.id===$?"Selected":"Select"}),e.jsxs(et,{children:[e.jsx(st,{asChild:!0,children:e.jsxs(h,{variant:"destructive",className:"ml-auto",disabled:O===m.id,children:[e.jsx(Ue,{className:"mr-2 h-5 w-5"}),O===m.id?"Deleting…":"Delete"]})}),e.jsxs(tt,{children:[e.jsxs(at,{children:[e.jsx(rt,{children:"Delete organization?"}),e.jsxs(it,{children:["This will permanently delete ",e.jsx("b",{children:m.name}),". This action cannot be undone."]})]}),e.jsxs(nt,{className:"sm:justify-between",children:[e.jsx(lt,{disabled:O===m.id,children:"Cancel"}),e.jsx(ot,{asChild:!0,disabled:O===m.id,children:e.jsx(h,{variant:"destructive",onClick:()=>H(m),children:"Confirm delete"})})]})]})]})]})]},m.id))}),e.jsx(ie,{open:u,onOpenChange:f,children:e.jsxs(oe,{className:"sm:max-w-[480px]",children:[e.jsxs(le,{children:[e.jsx(ce,{children:"Create organization"}),e.jsx(Ds,{children:"Set a name and a URL-friendly slug."})]}),e.jsx(ne,{...U,children:e.jsxs("form",{onSubmit:U.handleSubmit(j),className:"space-y-4",children:[e.jsx(v,{control:U.control,name:"name",render:({field:m})=>e.jsxs(b,{children:[e.jsx(N,{children:"Name"}),e.jsx(E,{children:e.jsx(z,{placeholder:"Acme Inc",autoFocus:!0,...m})}),e.jsx(jt,{children:"This is your organization’s display name."}),e.jsx(w,{})]})}),e.jsx(v,{control:U.control,name:"slug",render:({field:m})=>e.jsxs(b,{children:[e.jsx(N,{children:"Slug"}),e.jsx(E,{children:e.jsx(z,{placeholder:"acme-inc",...m,onChange:x=>{R.current=!0,m.onChange(x)},onBlur:x=>{const c=ht(x.target.value);U.setValue("slug",c,{shouldValidate:!0}),m.onBlur()}})}),e.jsx(jt,{children:"Lowercase, numbers and hyphens only."}),e.jsx(w,{})]})}),e.jsxs(de,{className:"flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>{U.reset(),f(!1),R.current=!1},children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!U.formState.isValid||U.formState.isSubmitting,children:U.formState.isSubmitting?"Creating...":"Create"})]})]})})]})})]})},ms=s=>(s??0).toLocaleString(),Ci=s=>{if(!isFinite(s)||s<=0)return"–";if(s<60)return`${s.toFixed(0)}s`;if(s<3600)return`${Math.floor(s/60)}m ${Math.floor(s%60)}s`;const t=Math.floor(s/3600),r=Math.floor(s%3600/60);return`${t}h ${r}m`};function _i(){const[s,t]=o.useState(null),[r,d]=o.useState([]),[u,f]=o.useState(!1),[$,C]=o.useState(null),[O,M]=o.useState(!0),[R,U]=o.useState(5e3),T=o.useCallback(async()=>{f(!0),C(null);try{const[j,V]=await Promise.all([g.get("/api/v1/jobs/kpi"),g.get("/api/v1/jobs/queues")]);t(j),d(V)}catch(j){C(j.message||String(j))}finally{f(!1)}},[]);o.useEffect(()=>{T()},[T]),o.useEffect(()=>{if(!O)return;const j=setInterval(T,R);return()=>clearInterval(j)},[O,R,T]);const P=o.useMemo(()=>({queues:r.length,running:r.reduce((j,V)=>j+V.Running,0),due:r.reduce((j,V)=>j+V.QueuedDue,0),future:r.reduce((j,V)=>j+V.QueuedFuture,0)}),[r]);return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("header",{className:"flex items-center justify-between gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Jobs Dashboard"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4",checked:O,onChange:j=>M(j.target.checked)}),"Auto refresh"]}),e.jsxs("select",{className:"border rounded px-2 py-1 text-sm",value:R,onChange:j=>U(parseInt(j.target.value)),children:[e.jsx("option",{value:3e3,children:"3s"}),e.jsx("option",{value:5e3,children:"5s"}),e.jsx("option",{value:1e4,children:"10s"}),e.jsx("option",{value:3e4,children:"30s"})]}),e.jsx("button",{className:"px-3 py-1.5 rounded bg-slate-900 text-white text-sm hover:opacity-90",onClick:T,disabled:u,children:u?"Refreshing…":"Refresh"})]})]}),$&&e.jsx("div",{className:"rounded border border-red-300 bg-red-50 text-red-800 p-3 text-sm",children:$}),e.jsxs("section",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-6",children:[e.jsx(xs,{label:"Running",value:ms(s?.RunningNow)}),e.jsx(xs,{label:"Due now",value:ms(s?.DueNow)}),e.jsx(xs,{label:"Scheduled",value:ms(s?.ScheduledFuture)}),e.jsx(xs,{label:"Succeeded (24h)",value:ms(s?.Succeeded24h)}),e.jsx(xs,{label:"Failed (24h)",value:ms(s?.Failed24h)}),e.jsx(xs,{label:"Retryable",value:ms(s?.Retryable)})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h2",{className:"text-lg font-medium",children:["Queues ",e.jsxs("span",{className:"text-slate-500 text-sm",children:["(",P.queues,")"]})]})}),e.jsx("div",{className:"overflow-x-auto rounded border",children:e.jsxs(be,{className:"min-w-full text-sm",children:[e.jsx(Ne,{children:e.jsxs(q,{children:[e.jsx(A,{children:"Queue"}),e.jsx(A,{className:"text-right",children:"Running"}),e.jsx(A,{className:"text-right",children:"Due"}),e.jsx(A,{className:"text-right",children:"Future"}),e.jsx(A,{className:"text-right",children:"Success 24h"}),e.jsx(A,{className:"text-right",children:"Failed 24h"}),e.jsx(A,{className:"text-right",children:"Avg Duration"})]})}),e.jsx(we,{children:r.map(j=>e.jsxs(q,{className:"border-t",children:[e.jsx(p,{children:j.QueueName}),e.jsx(p,{className:"text-right",children:j.Running}),e.jsx(p,{className:"text-right",children:j.QueuedDue}),e.jsx(p,{className:"text-right",children:j.QueuedFuture}),e.jsx(p,{className:"text-right",children:j.Success24h}),e.jsx(p,{className:"text-right",children:j.Failed24h}),e.jsx(p,{className:"text-right",children:Ci(j.AvgDurationSecs)})]},j.QueueName))})]})})]})]})}function xs({label:s,value:t}){return e.jsxs(Te,{children:[e.jsx(Pe,{children:e.jsx(Be,{children:s})}),e.jsx(Me,{children:e.jsx("div",{className:"mt-1 text-2xl font-semibold",children:t})})]})}function ki(){return e.jsxs(kn,{children:[e.jsx(se,{path:"/",element:e.jsx(Qs,{to:"/auth/login",replace:!0})}),e.jsxs(se,{path:"/auth",children:[e.jsx(se,{path:"login",element:e.jsx($r,{})}),e.jsx(se,{path:"register",element:e.jsx(Ir,{})}),e.jsx(se,{path:"forgot",element:e.jsx(Ar,{})}),e.jsx(se,{path:"reset",element:e.jsx(Pr,{})}),e.jsx(se,{path:"verify",element:e.jsx(Mr,{})})]}),e.jsx(se,{element:e.jsx(jr,{}),children:e.jsxs(se,{element:e.jsx(ur,{}),children:[e.jsx(se,{element:e.jsx(fr,{}),children:e.jsx(se,{path:"/admin",children:e.jsx(se,{path:"users",element:e.jsx(_r,{})})})}),e.jsxs(se,{path:"/core",children:[e.jsx(se,{path:"annotations",element:e.jsx(Vr,{})}),e.jsx(se,{path:"clusters",element:e.jsx(qr,{})}),e.jsx(se,{path:"labels",element:e.jsx(Yr,{})}),e.jsx(se,{path:"nodepools",element:e.jsx(ri,{})}),e.jsx(se,{path:"servers",element:e.jsx(li,{})}),e.jsx(se,{path:"taints",element:e.jsx(hi,{})})]}),e.jsx(se,{path:"/security",children:e.jsx(se,{path:"ssh",element:e.jsx(vi,{})})}),e.jsxs(se,{path:"/settings",children:[e.jsx(se,{path:"jobs",element:e.jsx(_i,{})}),e.jsx(se,{path:"orgs",element:e.jsx(Si,{})}),e.jsx(se,{path:"members",element:e.jsx(wi,{})}),e.jsx(se,{path:"me",element:e.jsx(Lr,{})})]}),e.jsx(se,{path:"/403",element:e.jsx(Nt,{})}),e.jsx(se,{path:"*",element:e.jsx(wt,{})})]})}),e.jsx(se,{path:"/403",element:e.jsx(Nt,{})}),e.jsx(se,{path:"*",element:e.jsx(wt,{})})]})}const Ai=({...s})=>{const{theme:t="system"}=yt();return e.jsx(xa,{theme:t,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...s})};function Ei({children:s,defaultTheme:t="system",storageKey:r="vite-ui-theme"}){return e.jsx(ha,{attribute:"class",defaultTheme:t,enableSystem:!0,storageKey:r,disableTransitionOnChange:!0,children:s})}ua.createRoot(document.getElementById("root")).render(e.jsx(o.StrictMode,{children:e.jsx(An,{children:e.jsxs(Ei,{defaultTheme:"system",storageKey:"dragon-theme",children:[e.jsx(ki,{}),e.jsx(Ai,{richColors:!0,position:"top-right"})]})})}));
|