Files
autoglue/internal/ui/dist/assets/index-CmZFDWt2.js
2025-09-03 17:09:39 +01:00

2 lines
94 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{t as Xs,m as Qs,r as c,j as e,n as ss,z as Es,F as Zs,C as et,p as st,q as tt,v as J,w as R,_ as Ne,x as Se,y as at,A as B,B as K,D as O,E as zs,G as ts,T as rt,J as nt,H as it}from"./vendor-DvippHRz.js";import{S as Me,R as lt,a as Os,C as Ls,b as As,T as Ds,D as Ts,P as $s,O as Ms,c as ot,d as dt,e as ct,f as mt,g as ut,A as xt,h as ht,i as jt,j as ft,k as gt,l as pt,m as vt,n as bt,I as wt,o as yt,p as Nt,q as St,r as Ct,s as kt,t as _t,u as It,v as Et,w as zt,x as Ot,y as Lt,z as At,B as Dt,E as Tt,V as $t,F as Mt,G as Pt,H as Ft,J as Rt,K as Vt,L as Ht,M as Ut,N as Bt,Q as Kt,U as Gt}from"./radix-DRmH1vcw.js";import{X as Ps,S as qt,M as Jt,L as Wt,C as Ee,H as Yt,A as Xt,B as Qt,a as Zt,T as ea,b as sa,c as Fs,d as ta,K as aa,F as ra,e as na,f as ia,g as la,U as vs,h as oa,i as da,j as ca,k as as,l as ma,m as ua,P as Pe,n as Je,o as we,p as Rs,R as Vs,q as Ce,r as xa,s as ha,t as ja,u as bs}from"./icons-DQ1I1M7X.js";import{u as We,L as ve,O as rs,N as ns,a as Fe,b as Hs,R as fa,c as T,B as ga}from"./router-CANfZtzM.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const m of document.querySelectorAll('link[rel="modulepreload"]'))n(m);new MutationObserver(m=>{for(const u of m)if(u.type==="childList")for(const g of u.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&n(g)}).observe(document,{childList:!0,subtree:!0});function a(m){const u={};return m.integrity&&(u.integrity=m.integrity),m.referrerPolicy&&(u.referrerPolicy=m.referrerPolicy),m.crossOrigin==="use-credentials"?u.credentials="include":m.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function n(m){if(m.ep)return;m.ep=!0;const u=a(m);fetch(m.href,u)}})();function h(...s){return Xs(Qs(s))}function ws(s){return s.toLowerCase().trim().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)+/g,"")}const Qe=768;function pa(){const[s,t]=c.useState(void 0);return c.useEffect(()=>{const a=window.matchMedia(`(max-width: ${Qe-1}px)`),n=()=>{t(window.innerWidth<Qe)};return a.addEventListener("change",n),t(window.innerWidth<Qe),()=>a.removeEventListener("change",n)},[]),!!s}const is=ss("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 x({className:s,variant:t,size:a,asChild:n=!1,...m}){const u=n?Me:"button";return e.jsx(u,{"data-slot":"button",className:h(is({variant:t,size:a,className:s})),...m})}function L({className:s,type:t,...a}){return e.jsx("input",{type:t,"data-slot":"input",className:h("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),...a})}function ze({className:s,orientation:t="horizontal",decorative:a=!0,...n}){return e.jsx(lt,{"data-slot":"separator",decorative:a,orientation:t,className:h("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),...n})}function va({...s}){return e.jsx(Os,{"data-slot":"sheet",...s})}function ba({...s}){return e.jsx($s,{"data-slot":"sheet-portal",...s})}function wa({className:s,...t}){return e.jsx(Ms,{"data-slot":"sheet-overlay",className:h("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 ya({className:s,children:t,side:a="right",...n}){return e.jsxs(ba,{children:[e.jsx(wa,{}),e.jsxs(Ls,{"data-slot":"sheet-content",className:h("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",a==="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",a==="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",a==="top"&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",a==="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),...n,children:[t,e.jsxs(As,{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(Ps,{className:"size-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Na({className:s,...t}){return e.jsx("div",{"data-slot":"sheet-header",className:h("flex flex-col gap-1.5 p-4",s),...t})}function Sa({className:s,...t}){return e.jsx(Ds,{"data-slot":"sheet-title",className:h("text-foreground font-semibold",s),...t})}function Ca({className:s,...t}){return e.jsx(Ts,{"data-slot":"sheet-description",className:h("text-muted-foreground text-sm",s),...t})}function fe({className:s,...t}){return e.jsx("div",{"data-slot":"skeleton",className:h("bg-accent animate-pulse rounded-md",s),...t})}function Ye({delayDuration:s=0,...t}){return e.jsx(ot,{"data-slot":"tooltip-provider",delayDuration:s,...t})}function ls({...s}){return e.jsx(Ye,{children:e.jsx(dt,{"data-slot":"tooltip",...s})})}function os({...s}){return e.jsx(ct,{"data-slot":"tooltip-trigger",...s})}function ds({className:s,sideOffset:t=0,children:a,...n}){return e.jsx(mt,{children:e.jsxs(ut,{"data-slot":"tooltip-content",sideOffset:t,className:h("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),...n,children:[a,e.jsx(xt,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}const ka="sidebar_state",_a=3600*24*7,Ia="16rem",Ea="18rem",za="3rem",Oa="b",Us=c.createContext(null);function Bs(){const s=c.useContext(Us);if(!s)throw new Error("useSidebar must be used within a SidebarProvider.");return s}function La({defaultOpen:s=!0,open:t,onOpenChange:a,className:n,style:m,children:u,...g}){const j=pa(),[b,f]=c.useState(!1),[k,p]=c.useState(s),_=t??k,I=c.useCallback(o=>{const d=typeof o=="function"?o(_):o;a?a(d):p(d),document.cookie=`${ka}=${d}; path=/; max-age=${_a}`},[a,_]),$=c.useCallback(()=>j?f(o=>!o):I(o=>!o),[j,I,f]);c.useEffect(()=>{const o=d=>{d.key===Oa&&(d.metaKey||d.ctrlKey)&&(d.preventDefault(),$())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[$]);const M=_?"expanded":"collapsed",F=c.useMemo(()=>({state:M,open:_,setOpen:I,isMobile:j,openMobile:b,setOpenMobile:f,toggleSidebar:$}),[M,_,I,j,b,f,$]);return e.jsx(Us.Provider,{value:F,children:e.jsx(Ye,{delayDuration:0,children:e.jsx("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":Ia,"--sidebar-width-icon":za,...m},className:h("group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",n),...g,children:u})})})}function Aa({side:s="left",variant:t="sidebar",collapsible:a="offcanvas",className:n,children:m,...u}){const{isMobile:g,state:j,openMobile:b,setOpenMobile:f}=Bs();return a==="none"?e.jsx("div",{"data-slot":"sidebar",className:h("bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",n),...u,children:m}):g?e.jsx(va,{open:b,onOpenChange:f,...u,children:e.jsxs(ya,{"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":Ea},side:s,children:[e.jsxs(Na,{className:"sr-only",children:[e.jsx(Sa,{children:"Sidebar"}),e.jsx(Ca,{children:"Displays the mobile sidebar."})]}),e.jsx("div",{className:"flex h-full w-full flex-col",children:m})]})}):e.jsxs("div",{className:"group peer text-sidebar-foreground hidden md:block","data-state":j,"data-collapsible":j==="collapsed"?a:"","data-variant":t,"data-side":s,"data-slot":"sidebar",children:[e.jsx("div",{"data-slot":"sidebar-gap",className:h("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:h("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",n),...u,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:m})})]})}function Da({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:h("flex flex-col gap-2 p-2",s),...t})}function Ta({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-footer","data-sidebar":"footer",className:h("flex flex-col gap-2 p-2",s),...t})}function $a({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:h("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",s),...t})}function Ma({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:h("relative flex w-full min-w-0 flex-col p-2",s),...t})}function Pa({className:s,asChild:t=!1,...a}){const n=t?Me:"div";return e.jsx(n,{"data-slot":"sidebar-group-label","data-sidebar":"group-label",className:h("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),...a})}function Fa({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-group-content","data-sidebar":"group-content",className:h("w-full text-sm",s),...t})}function Ra({className:s,...t}){return e.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:h("flex w-full min-w-0 flex-col gap-1",s),...t})}function Va({className:s,...t}){return e.jsx("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:h("group/menu-item relative",s),...t})}const Ha=ss("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 Ua({asChild:s=!1,isActive:t=!1,variant:a="default",size:n="default",tooltip:m,className:u,...g}){const j=s?Me:"button",{isMobile:b,state:f}=Bs(),k=e.jsx(j,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":n,"data-active":t,className:h(Ha({variant:a,size:n}),u),...g});return m?(typeof m=="string"&&(m={children:m}),e.jsxs(ls,{children:[e.jsx(os,{asChild:!0,children:k}),e.jsx(ds,{side:"right",align:"center",hidden:f!=="collapsed"||b,...m})]})):k}const Ge="";class Y extends Error{status;body;constructor(t,a,n){super(a),this.status=t,this.body=n}}function Ba(s){const t={};if(!s)return t;if(s instanceof Headers)s.forEach((a,n)=>t[n]=a);else if(Array.isArray(s))for(const[a,n]of s)t[a]=n;else Object.assign(t,s);return t}function Ka(){const s={},t=localStorage.getItem("access_token");return t&&(s.Authorization=`Bearer ${t}`),s}function Ga(){const s=localStorage.getItem("active_org_id");return s?{"X-Org-ID":s}:{}}async function ke(s,t,a,n={}){const u={...{"Content-Type":"application/json"},...n.auth===!1?{}:Ka(),...Ga(),...Ba(n.headers)},g=await fetch(`${Ge}${s}`,{method:t,headers:u,body:a===void 0?void 0:JSON.stringify(a),...n}),b=(g.headers.get("content-type")||"").includes("application/json"),f=b?await g.json().catch(()=>{}):await g.text().catch(()=>"");if(!g.ok){const k=b&&f&&typeof f=="object"&&"error"in f&&f.error||b&&f&&typeof f=="object"&&"message"in f&&f.message||typeof f=="string"&&f||`HTTP ${g.status}`;throw new Y(g.status,String(k),f)}return console.debug("API ->",t,`${Ge}${s}`,u),b?f:void 0}const z={get:(s,t)=>ke(s,"GET",void 0,t),post:(s,t,a)=>ke(s,"POST",t,a),put:(s,t,a)=>ke(s,"PUT",t,a),patch:(s,t,a)=>ke(s,"PATCH",t,a),delete:(s,t)=>ke(s,"DELETE",void 0,t)};function qa(s){return s&&(s.user||s.user_id)}function Ks(s){return qa(s)?.role==="admin"}function Ja(s){return(s?.org_role??"")==="admin"}const ue={isAuthenticated(){return!!localStorage.getItem("access_token")},async login(s,t){const a=await z.post("/api/v1/auth/login",{email:s,password:t});localStorage.setItem("access_token",a.access_token),localStorage.setItem("refresh_token",a.refresh_token)},async register(s,t,a){await z.post("/api/v1/auth/register",{name:s,email:t,password:a})},async me(){return await z.get("/api/v1/auth/me")},async logout(){const s=localStorage.getItem("refresh_token");if(s)try{await z.post("/api/v1/auth/logout",{refresh_token:s})}catch{}localStorage.removeItem("access_token"),localStorage.removeItem("refresh_token")},async forgot(s){await z.post("/api/v1/auth/password/forgot",{email:s})},async reset(s,t){await z.post("/api/v1/auth/password/reset",{token:s,new_password:t})},async verify(s){const t=await fetch(`${Ge}/api/v1/auth/verify?token=${encodeURIComponent(s)}`);if(!t.ok){const a=await t.text();throw new Error(a)}}};function Wa({...s}){return e.jsx(ht,{"data-slot":"collapsible",...s})}function Ya({...s}){return e.jsx(jt,{"data-slot":"collapsible-trigger",...s})}function Xa({...s}){return e.jsx(ft,{"data-slot":"collapsible-content",...s})}function Re({...s}){return e.jsx(gt,{"data-slot":"dropdown-menu",...s})}function Ve({...s}){return e.jsx(pt,{"data-slot":"dropdown-menu-trigger",...s})}function He({className:s,sideOffset:t=4,...a}){return e.jsx(vt,{children:e.jsx(bt,{"data-slot":"dropdown-menu-content",sideOffset:t,className:h("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),...a})})}function me({className:s,inset:t,variant:a="default",...n}){return e.jsx(wt,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":a,className:h("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),...n})}function Qa(){const{setTheme:s,theme:t}=Es();return e.jsxs(Re,{children:[e.jsx(Ve,{asChild:!0,children:e.jsx(x,{variant:"outline",size:"icon","aria-label":"Toggle theme",children:t==="light"?e.jsx(qt,{className:"h-5 w-5"}):t==="dark"?e.jsx(Jt,{className:"h-5 w-5"}):e.jsx(Wt,{className:"h-5 w-5"})})}),e.jsxs(He,{align:"end",children:[e.jsxs(me,{onClick:()=>s("light"),children:[t==="light"&&e.jsx(Ee,{}),"Light"]}),e.jsxs(me,{onClick:()=>s("dark"),children:[t==="dark"&&e.jsx(Ee,{}),"Dark"]}),e.jsxs(me,{onClick:()=>s("system"),children:[t==="system"&&e.jsx(Ee,{}),"System"]})]})]})}const es="active_org_id",be="active-org-changed",Le="orgs-changed";function je(){return localStorage.getItem(es)}function Oe(s){s?localStorage.setItem(es,s):localStorage.removeItem(es),window.dispatchEvent(new CustomEvent(be,{detail:s}))}function ys(){window.dispatchEvent(new Event(Le))}const Za=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(null);async function m(){try{const j=await z.get("/api/v1/orgs");t(j),!je()&&j.length>0&&(Oe(j[0].id),n(j[0].id))}catch(j){const b=j instanceof Y?j.message:"Failed to load organizations";console.error(b)}}c.useEffect(()=>{n(je()),m();const j=k=>{k.key==="active_org_id"&&n(k.newValue)};window.addEventListener("storage",j);const b=k=>n(k.detail??null),f=()=>void m();return window.addEventListener(be,b),window.addEventListener(Le,f),()=>{window.removeEventListener("storage",j),window.removeEventListener(be,b),window.removeEventListener(Le,f)}},[]);const u=j=>{Oe(j),n(j)},g=s.find(j=>j.id===a)?.name??"Select Org";return e.jsxs(Re,{children:[e.jsx(Ve,{asChild:!0,children:e.jsx(x,{variant:"outline",className:"w-full justify-start",children:g})}),e.jsx(He,{className:"w-48",children:s.length===0?e.jsx(me,{disabled:!0,children:"No organizations"}):s.map(j=>e.jsx(me,{onClick:()=>u(j.id),className:j.id===a?"font-semibold":void 0,children:j.name},j.id))})]})},er=[{label:"Dashboard",icon:Yt,to:"/dashboard"},{label:"Core",icon:ta,items:[{label:"Cluster",to:"/core/clusters",icon:Xt},{label:"Node Pools",icon:Qt,to:"/core/nodepools"},{label:"Annotations",icon:Zt,to:"/core/annotations"},{label:"Labels",icon:ea,to:"/core/labels"},{label:"Taints",icon:sa,to:"/core/taints"},{label:"Servers",icon:Fs,to:"/core/servers"}]},{label:"Security",icon:na,items:[{label:"Keys & Tokens",icon:aa,to:"/security/keys"},{label:"SSH Keys",to:"/security/ssh",icon:ra}]},{label:"Tasks",icon:ia,items:[]},{label:"Settings",icon:da,items:[{label:"Organizations",to:"/settings/orgs",icon:la},{label:"Members",to:"/settings/members",icon:vs},{label:"Profile",to:"/settings/me",icon:oa}]},{label:"Admin",icon:ca,requiresAdmin:!0,items:[{label:"Users",to:"/admin/users",icon:vs,requiresAdmin:!0}]}];function Gs(s,t,a){return s.filter(n=>!(n.requiresAdmin&&!t||n.requiresOrgAdmin&&!a)).map(n=>({...n,items:n.items?Gs(n.items,t,a):void 0})).filter(n=>!n.items||n.items.length>0)}const qs=({item:s})=>{const t=We(),a=s.icon;return s.to?e.jsxs(ve,{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(a,{className:"mr-4 h-4 w-4"}),s.label]}):s.items?e.jsx(Wa,{defaultOpen:!0,className:"group/collapsible",children:e.jsxs(Ma,{children:[e.jsx(Pa,{asChild:!0,children:e.jsxs(Ya,{children:[e.jsx(a,{className:"mr-4 h-4 w-4"}),s.label,e.jsx(as,{className:"ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180"})]})}),e.jsx(Xa,{children:e.jsx(Fa,{children:e.jsx(Ra,{children:s.items.map((n,m)=>e.jsx(Va,{children:e.jsx(Ua,{asChild:!0,children:e.jsx(qs,{item:n})})},m))})})})]})}):null},sr=()=>{const[s,t]=c.useState(null),[a,n]=c.useState(!0);c.useEffect(()=>{let u=!0;return(async()=>{try{const g=await ue.me();if(!u)return;t(g)}catch{}finally{n(!1)}})(),()=>{u=!1}},[]);const m=c.useMemo(()=>{const u=Ks(s),g=Ja(s);return Gs(er,u,g)},[s]);return a?e.jsx("div",{className:"p-6",children:"Loading…"}):e.jsxs(Aa,{children:[e.jsx(Da,{className:"flex items-center justify-between p-4",children:e.jsx("h1",{className:"text-xl font-bold",children:"AutoGlue"})}),e.jsx($a,{children:m.map((u,g)=>e.jsx(qs,{item:u},g))}),e.jsxs(Ta,{className:"space-y-2 p-4",children:[e.jsx(Za,{}),e.jsx(Qa,{}),e.jsx(x,{onClick:()=>{localStorage.clear(),window.location.reload()},className:"w-full",children:"Logout"})]})]})};function tr(){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(ma,{className:"h-5 w-5"})})})]})})}function ar(){return e.jsx("div",{className:"flex h-screen",children:e.jsxs(La,{children:[e.jsx(sr,{}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx("main",{className:"flex-1 overflow-auto p-4",children:e.jsx(rs,{})}),e.jsx(tr,{})]})]})})}function rr({children:s}){const t=We();return ue.isAuthenticated()?s?e.jsx(e.Fragment,{children:s}):e.jsx(rs,{}):e.jsx(ns,{to:"/auth/login",state:{from:t},replace:!0})}function nr({children:s}){const[t,a]=c.useState(!0),[n,m]=c.useState(!1),u=We();return c.useEffect(()=>{let g=!0;return(async()=>{try{const j=await ue.me();if(!g)return;m(Ks(j))}catch{if(!g)return;m(!1)}finally{if(a(!1),!g)return}})(),()=>{g=!1}},[]),t?null:n?s?e.jsx(e.Fragment,{children:s}):e.jsx(rs,{}):e.jsx(ns,{to:"/403",replace:!0,state:{from:u}})}function cs({...s}){return e.jsx(yt,{"data-slot":"alert-dialog",...s})}function ms({...s}){return e.jsx(Nt,{"data-slot":"alert-dialog-trigger",...s})}function ir({...s}){return e.jsx(Et,{"data-slot":"alert-dialog-portal",...s})}function lr({className:s,...t}){return e.jsx(zt,{"data-slot":"alert-dialog-overlay",className:h("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 us({className:s,...t}){return e.jsxs(ir,{children:[e.jsx(lr,{}),e.jsx(St,{"data-slot":"alert-dialog-content",className:h("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 xs({className:s,...t}){return e.jsx("div",{"data-slot":"alert-dialog-header",className:h("flex flex-col gap-2 text-center sm:text-left",s),...t})}function hs({className:s,...t}){return e.jsx("div",{"data-slot":"alert-dialog-footer",className:h("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...t})}function js({className:s,...t}){return e.jsx(Ct,{"data-slot":"alert-dialog-title",className:h("text-lg font-semibold",s),...t})}function fs({className:s,...t}){return e.jsx(kt,{"data-slot":"alert-dialog-description",className:h("text-muted-foreground text-sm",s),...t})}function gs({className:s,...t}){return e.jsx(It,{className:h(is(),s),...t})}function ps({className:s,...t}){return e.jsx(_t,{className:h(is({variant:"outline"}),s),...t})}function oe({className:s,...t}){return e.jsx("div",{"data-slot":"card",className:h("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",s),...t})}function de({className:s,...t}){return e.jsx("div",{"data-slot":"card-header",className:h("@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 he({className:s,...t}){return e.jsx("div",{"data-slot":"card-title",className:h("leading-none font-semibold",s),...t})}function ce({className:s,...t}){return e.jsx("div",{"data-slot":"card-content",className:h("px-6",s),...t})}function Ae({className:s,...t}){return e.jsx("div",{"data-slot":"card-footer",className:h("flex items-center px-6 [.border-t]:pt-6",s),...t})}function ae({...s}){return e.jsx(Os,{"data-slot":"dialog",...s})}function Ue({...s}){return e.jsx(Ot,{"data-slot":"dialog-trigger",...s})}function or({...s}){return e.jsx($s,{"data-slot":"dialog-portal",...s})}function dr({className:s,...t}){return e.jsx(Ms,{"data-slot":"dialog-overlay",className:h("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 re({className:s,children:t,showCloseButton:a=!0,...n}){return e.jsxs(or,{"data-slot":"dialog-portal",children:[e.jsx(dr,{}),e.jsxs(Ls,{"data-slot":"dialog-content",className:h("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),...n,children:[t,a&&e.jsxs(As,{"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(Ps,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function ne({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-header",className:h("flex flex-col gap-2 text-center sm:text-left",s),...t})}function ie({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-footer",className:h("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...t})}function le({className:s,...t}){return e.jsx(Ds,{"data-slot":"dialog-title",className:h("text-lg leading-none font-semibold",s),...t})}function qe({className:s,...t}){return e.jsx(Ts,{"data-slot":"dialog-description",className:h("text-muted-foreground text-sm",s),...t})}function cr({className:s,...t}){return e.jsx(Lt,{"data-slot":"label",className:h("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 G=Zs,Js=c.createContext({}),w=({...s})=>e.jsx(Js.Provider,{value:{name:s.name},children:e.jsx(et,{...s})}),Xe=()=>{const s=c.useContext(Js),t=c.useContext(Ws),{getFieldState:a}=st(),n=tt({name:s.name}),m=a(s.name,n);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:u}=t;return{id:u,name:s.name,formItemId:`${u}-form-item`,formDescriptionId:`${u}-form-item-description`,formMessageId:`${u}-form-item-message`,...m}},Ws=c.createContext({});function y({className:s,...t}){const a=c.useId();return e.jsx(Ws.Provider,{value:{id:a},children:e.jsx("div",{"data-slot":"form-item",className:h("grid gap-2",s),...t})})}function N({className:s,...t}){const{error:a,formItemId:n}=Xe();return e.jsx(cr,{"data-slot":"form-label","data-error":!!a,className:h("data-[error=true]:text-destructive",s),htmlFor:n,...t})}function C({...s}){const{error:t,formItemId:a,formDescriptionId:n,formMessageId:m}=Xe();return e.jsx(Me,{"data-slot":"form-control",id:a,"aria-describedby":t?`${n} ${m}`:`${n}`,"aria-invalid":!!t,...s})}function Ns({className:s,...t}){const{formDescriptionId:a}=Xe();return e.jsx("p",{"data-slot":"form-description",id:a,className:h("text-muted-foreground text-sm",s),...t})}function S({className:s,...t}){const{error:a,formMessageId:n}=Xe(),m=a?String(a?.message??""):t.children;return m?e.jsx("p",{"data-slot":"form-message",id:n,className:h("text-destructive text-sm",s),...t,children:m}):null}function Z({...s}){return e.jsx(At,{"data-slot":"select",...s})}function ee({...s}){return e.jsx($t,{"data-slot":"select-value",...s})}function se({className:s,size:t="default",children:a,...n}){return e.jsxs(Dt,{"data-slot":"select-trigger","data-size":t,className:h("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),...n,children:[a,e.jsx(Tt,{asChild:!0,children:e.jsx(as,{className:"size-4 opacity-50"})})]})}function te({className:s,children:t,position:a="popper",...n}){return e.jsx(Mt,{children:e.jsxs(Pt,{"data-slot":"select-content",className:h("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",a==="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:a,...n,children:[e.jsx(mr,{}),e.jsx(Ft,{className:h("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),e.jsx(ur,{})]})})}function q({className:s,children:t,...a}){return e.jsxs(Rt,{"data-slot":"select-item",className:h("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),...a,children:[e.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:e.jsx(Vt,{children:e.jsx(Ee,{className:"size-4"})})}),e.jsx(Ht,{children:t})]})}function mr({className:s,...t}){return e.jsx(Ut,{"data-slot":"select-scroll-up-button",className:h("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(ua,{className:"size-4"})})}function ur({className:s,...t}){return e.jsx(Bt,{"data-slot":"select-scroll-down-button",className:h("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(as,{className:"size-4"})})}const xr=J({name:R().min(1,"Name required"),email:Se("Enter a valid email"),role:Ne(["user","admin"]),password:R().min(8,"Min 8 characters")}),hr=J({name:R().min(1,"Name required"),email:Se("Enter a valid email"),role:Ne(["user","admin"]),password:R().min(8,"Min 8 characters").optional().or(at(""))});function jr(){const[s,t]=c.useState([]),[a,n]=c.useState(!0),[m,u]=c.useState(!1),[g,j]=c.useState(!1),[b,f]=c.useState(null),[k,p]=c.useState(null),_=B({resolver:K(xr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}}),I=B({resolver:K(hr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}});async function $(){n(!0);try{const l=await z.get("/api/v1/admin/users?page=1&page_size=100");t(l.users??[])}catch(l){O.error(l instanceof Y?l.message:"Failed to load users")}finally{n(!1)}}c.useEffect(()=>{$()},[]);async function M(l){try{const v=await z.post("/api/v1/admin/users",l);t(A=>[v,...A]),u(!1),_.reset({name:"",email:"",role:"user",password:""}),O.success(`Created ${v.email}`)}catch(v){O.error(v instanceof Y?v.message:"Failed to create user")}}function F(l){f(l),I.reset({name:l.name||"",email:l.email,role:l.role??"user",password:""}),j(!0)}async function o(l){if(!b)return;const v={name:l.name,email:l.email,role:l.role};l.password&&l.password.length>=8&&(v.password=l.password);try{const A=await z.patch(`/api/v1/admin/users/${b.id}`,v);t(H=>H.map(V=>V.id===A.id?A:V)),j(!1),f(null),O.success(`Updated ${A.email}`)}catch(A){O.error(A instanceof Y?A.message:"Failed to update user")}}async function d(l){try{p(l),await z.delete(`/api/v1/admin/users/${l}`),t(v=>v.filter(A=>A.id!==l)),O.success("User deleted")}catch(v){O.error(v instanceof Y?v.message:"Failed to delete user")}finally{p(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(x,{onClick:()=>u(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"New user"]})]}),e.jsx(ze,{}),a?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(l=>e.jsxs(oe,{className:"flex flex-col",children:[e.jsx(de,{children:e.jsx(he,{className:"text-base",children:l.name||l.email})}),e.jsxs(ce,{className:"text-muted-foreground space-y-1 text-sm",children:[e.jsxs("div",{children:["Email: ",l.email]}),e.jsxs("div",{children:["Role: ",l.role]}),e.jsxs("div",{children:["Verified: ",l.email_verified?"Yes":"No"]}),e.jsxs("div",{children:["Joined: ",new Date(l.created_at).toLocaleString()]})]}),e.jsxs(Ae,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(x,{variant:"outline",onClick:()=>F(l),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(x,{variant:"destructive",disabled:k===l.id,children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),k===l.id?"Deleting…":"Delete"]})}),e.jsxs(us,{children:[e.jsxs(xs,{children:[e.jsx(js,{children:"Delete user?"}),e.jsxs(fs,{children:["This will permanently delete ",e.jsx("b",{children:l.email}),"."]})]}),e.jsxs(hs,{className:"sm:justify-between",children:[e.jsx(ps,{disabled:k===l.id,children:"Cancel"}),e.jsx(gs,{asChild:!0,disabled:k===l.id,children:e.jsx(x,{variant:"destructive",onClick:()=>d(l.id),children:"Confirm delete"})})]})]})]})]})]},l.id))}),e.jsx(ae,{open:m,onOpenChange:u,children:e.jsxs(re,{className:"sm:max-w-[520px]",children:[e.jsxs(ne,{children:[e.jsx(le,{children:"Create user"}),e.jsx(qe,{children:"Add a new user account."})]}),e.jsx(G,{..._,children:e.jsxs("form",{onSubmit:_.handleSubmit(M),className:"grid gap-4 py-2",children:[e.jsx(w,{name:"name",control:_.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{...l,placeholder:"Jane Doe"})}),e.jsx(S,{})]})}),e.jsx(w,{name:"email",control:_.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{type:"email",...l,placeholder:"jane@example.com"})}),e.jsx(S,{})]})}),e.jsx(w,{name:"role",control:_.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Z,{value:l.value,onValueChange:l.onChange,children:[e.jsx(C,{children:e.jsx(se,{className:"w-[200px]",children:e.jsx(ee,{placeholder:"Select role"})})}),e.jsxs(te,{children:[e.jsx(q,{value:"user",children:"User"}),e.jsx(q,{value:"admin",children:"Admin"})]})]}),e.jsx(S,{})]})}),e.jsx(w,{name:"password",control:_.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Password"}),e.jsx(C,{children:e.jsx(L,{type:"password",...l,placeholder:"••••••••"})}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:!_.formState.isValid||_.formState.isSubmitting,children:_.formState.isSubmitting?"Creating…":"Create"})]})]})})]})}),e.jsx(ae,{open:g,onOpenChange:j,children:e.jsxs(re,{className:"sm:max-w-[520px]",children:[e.jsxs(ne,{children:[e.jsx(le,{children:"Edit user"}),e.jsx(qe,{children:"Update user details. Leave password blank to keep it unchanged."})]}),e.jsx(G,{...I,children:e.jsxs("form",{onSubmit:I.handleSubmit(o),className:"grid gap-4 py-2",children:[e.jsx(w,{name:"name",control:I.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{...l})}),e.jsx(S,{})]})}),e.jsx(w,{name:"email",control:I.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{type:"email",...l})}),e.jsx(S,{})]})}),e.jsx(w,{name:"role",control:I.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Z,{value:l.value,onValueChange:l.onChange,children:[e.jsx(C,{children:e.jsx(se,{className:"w-[200px]",children:e.jsx(ee,{placeholder:"Select role"})})}),e.jsxs(te,{children:[e.jsx(q,{value:"user",children:"User"}),e.jsx(q,{value:"admin",children:"Admin"})]})]}),e.jsx(S,{})]})}),e.jsx(w,{name:"password",control:I.control,render:({field:l})=>e.jsxs(y,{children:[e.jsx(N,{children:"New password (optional)"}),e.jsx(C,{children:e.jsx(L,{type:"password",...l,placeholder:"Leave blank to keep"})}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:!I.formState.isValid||I.formState.isSubmitting,children:I.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})}const fr=J({email:Se()});function gr(){const s=B({resolver:K(fr),defaultValues:{email:""}});async function t(a){try{await ue.forgot(a.email),O.success("If that email exists, we've sent instructions.")}catch(n){O.error(n.message||"Something went wrong")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"Forgot password"})}),e.jsx(ce,{children:e.jsx(G,{...s,children:e.jsxs("form",{onSubmit:s.handleSubmit(t),className:"space-y-4",children:[e.jsx(w,{name:"email",control:s.control,render:({field:a})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{placeholder:"you@example.com",...a})}),e.jsx(S,{})]})}),e.jsx(x,{type:"submit",className:"w-full",children:"Send reset link"})]})})})]})})}const pr=J({email:Se(),password:R().min(6)});function vr(){const s=Fe(),t=We(),a=B({resolver:K(pr),defaultValues:{email:"",password:""}});async function n(m){try{await ue.login(m.email,m.password),O.success("Welcome back!");const u=t.state?.from?.pathname??"/settings/me";s(u,{replace:!0})}catch(u){O.error(u.message||"Login failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"Sign in"})}),e.jsxs(ce,{children:[e.jsx(G,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(n),className:"space-y-4",children:[e.jsx(w,{name:"email",control:a.control,render:({field:m})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{placeholder:"you@example.com",...m})}),e.jsx(S,{})]})}),e.jsx(w,{name:"password",control:a.control,render:({field:m})=>e.jsxs(y,{children:[e.jsx(N,{children:"Password"}),e.jsx(C,{children:e.jsx(L,{type:"password",placeholder:"••••••••",...m})}),e.jsx(S,{})]})}),e.jsx(x,{type:"submit",className:"w-full",children:"Sign in"})]})}),e.jsxs("div",{className:"mt-4 flex justify-between text-sm",children:[e.jsx(ve,{to:"/auth/forgot",className:"underline",children:"Forgot password?"}),e.jsx(ve,{to:"/auth/register",className:"underline",children:"Create an account"})]})]})]})})}function br(){const[s,t]=c.useState(null),a=Fe();c.useEffect(()=>{(async()=>{try{const m=await ue.me();t(m)}catch(m){O.error(m.message||"Failed to load profile")}})()},[]);async function n(){await ue.logout(),a("/auth/login")}return e.jsx("div",{className:"mx-auto max-w-xl",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"My Account"})}),e.jsxs(ce,{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(x,{onClick:n,children:"Sign out"})]})]})})}const wr=J({name:R().min(2),email:Se(),password:R().min(6)});function yr(){const s=Fe(),t=B({resolver:K(wr),defaultValues:{name:"",email:"",password:""}});async function a(n){try{await ue.register(n.name,n.email,n.password),O.success("Account created! Check your email to verify."),s("/auth/login")}catch(m){O.error(m.message||"Registration failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"Create account"})}),e.jsxs(ce,{children:[e.jsx(G,{...t,children:e.jsxs("form",{onSubmit:t.handleSubmit(a),className:"space-y-4",children:[e.jsx(w,{name:"name",control:t.control,render:({field:n})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{placeholder:"Jane Doe",...n})}),e.jsx(S,{})]})}),e.jsx(w,{name:"email",control:t.control,render:({field:n})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{placeholder:"you@example.com",...n})}),e.jsx(S,{})]})}),e.jsx(w,{name:"password",control:t.control,render:({field:n})=>e.jsxs(y,{children:[e.jsx(N,{children:"Password"}),e.jsx(C,{children:e.jsx(L,{type:"password",placeholder:"••••••••",...n})}),e.jsx(S,{})]})}),e.jsx(x,{type:"submit",className:"w-full",children:"Create account"})]})}),e.jsxs("div",{className:"mt-4 text-sm",children:["Already have an account?"," ",e.jsx(ve,{to:"/auth/login",className:"underline",children:"Sign in"})]})]})]})})}const Nr=J({new_password:R().min(6)});function Sr(){const[s]=Hs(),t=s.get("token"),a=B({resolver:K(Nr),defaultValues:{new_password:""}}),n=Fe();async function m(u){if(!t){O.error("Missing token");return}try{await ue.reset(t,u.new_password),O.success("Password updated. Please sign in."),n("/auth/login")}catch(g){O.error(g.message||"Reset failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"Reset password"})}),e.jsxs(ce,{children:[e.jsx(G,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(m),className:"space-y-4",children:[e.jsx(w,{name:"new_password",control:a.control,render:({field:u})=>e.jsxs(y,{children:[e.jsx(N,{children:"New password"}),e.jsx(C,{children:e.jsx(L,{type:"password",placeholder:"••••••••",...u})}),e.jsx(S,{})]})}),e.jsx(x,{type:"submit",className:"w-full",children:"Update password"})]})}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsx(ve,{to:"/auth/login",className:"underline",children:"Back to sign in"})})]})]})})}function Cr(){const[s]=Hs(),t=s.get("token"),[a,n]=c.useState("idle");return c.useEffect(()=>{async function m(){if(!t){n("error");return}try{await ue.verify(t),n("ok")}catch(u){O.error(u.message||"Verification failed"),n("error")}}m()},[t]),e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(he,{children:"Email verification"})}),e.jsxs(ce,{className:"space-y-3",children:[a==="idle"&&e.jsx("p",{children:"Verifying…"}),a==="ok"&&e.jsxs("div",{children:[e.jsx("p",{children:"Your email has been verified. You can now sign in."}),e.jsx(x,{asChild:!0,className:"mt-3",children:e.jsx(ve,{to:"/auth/login",children:"Go to sign in"})})]}),a==="error"&&e.jsxs("div",{children:[e.jsx("p",{children:"Verification failed. Please request a new verification email."}),e.jsx(x,{asChild:!0,className:"mt-3",children:e.jsx(ve,{to:"/auth/login",children:"Back to sign in"})})]})]})]})})}const kr=()=>e.jsx("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:"Annotations"})})}),_r=()=>e.jsx("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:"Clusters"})})});function De({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:h("w-full caption-bottom text-sm",s),...t})})}function Te({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:h("[&_tr]:border-b",s),...t})}function $e({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:h("[&_tr:last-child]:border-0",s),...t})}function W({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:h("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t})}function P({className:s,...t}){return e.jsx("th",{"data-slot":"table-head",className:h("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 D({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:h("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}const Ir=J({key:R().min(2),value:R().min(2)}),Er=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(!1),[m,u]=c.useState(null),[g,j]=c.useState(!1);async function b(){n(!0),u(null);try{const p=await z.get("/api/v1/labels");console.log(JSON.stringify(p)),t(p)}catch(p){console.error(p)}finally{n(!1)}}c.useEffect(()=>{b()},[]);const f=B({resolver:K(Ir),defaultValues:{key:"",value:""}}),k=async p=>{const _={key:p.key,value:p.value};await z.post("/api/v1/labels",_),j(!1),f.reset(),await b()};return a?e.jsx("div",{className:"p-6",children:"Loading servers…"}):m?e.jsx("div",{className:"p-6 text-red-500",children:m}):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(ae,{open:g,onOpenChange:j,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{onClick:()=>j(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"Create Label"]})}),e.jsxs(re,{className:"sm:max-w-lg",children:[e.jsx(ne,{children:e.jsx(le,{children:"Create Label"})}),e.jsx(G,{...f,children:e.jsxs("form",{onSubmit:f.handleSubmit(k),className:"space-y-4",children:[e.jsx(w,{control:f.control,name:"key",render:({field:p})=>e.jsxs(y,{children:[e.jsx(N,{children:"Key"}),e.jsx(C,{children:e.jsx(L,{placeholder:"app.kubernetes.io/managed-by",...p})}),e.jsx(S,{})]})}),e.jsx(w,{control:f.control,name:"value",render:({field:p})=>e.jsxs(y,{children:[e.jsx(N,{children:"Value"}),e.jsx(C,{children:e.jsx(L,{placeholder:"GlueOps",...p})}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:f.formState.isSubmitting,children:f.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(De,{children:[e.jsx(Te,{children:e.jsxs(W,{children:[e.jsx(P,{children:"Key"}),e.jsx(P,{children:"Values"}),e.jsx(P,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsx($e,{children:s.map(p=>e.jsxs(W,{children:[e.jsx(D,{children:p.key}),e.jsx(D,{children:p.value}),e.jsx(D,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Edit"]}),e.jsxs(x,{variant:"destructive",size:"sm",children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"Delete"]})]})})]},p.id))})]})})})]})},zr=ss("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 Be({className:s,variant:t,asChild:a=!1,...n}){const m=a?Me:"span";return e.jsx(m,{"data-slot":"badge",className:h(zr({variant:t}),s),...n})}function Ss({className:s,...t}){return e.jsx(Kt,{"data-slot":"checkbox",className:h("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(Gt,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(Ee,{className:"size-3.5"})})})}const Or=J({name:R().trim().min(1,"Name is required").max(120,"Max 120 chars"),server_ids:zs(ts()).optional().default([])}),Lr=J({name:R().trim().min(1,"Name is required").max(120,"Max 120 chars")}),Ar=J({server_ids:zs(ts()).min(1,"Pick at least one server")});function Cs({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Be,{variant:t,className:"capitalize",children:s||"unknown"})}function Ke(s,t=12){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}${s.slice(-t)}`}function ks(s){const t=s.ip||s.ip_address,a=s.hostname||t||s.id,n=s.role?` · ${s.role}`:"";return`${a}${n}`}const Dr=()=>{const[s,t]=c.useState(!0),[a,n]=c.useState([]),[m,u]=c.useState([]),[g,j]=c.useState(null),[b,f]=c.useState(""),[k,p]=c.useState(!1),[_,I]=c.useState(null),[$,M]=c.useState(null);async function F(){t(!0),j(null);try{const[r,E]=await Promise.all([z.get("/api/v1/node-pools?include=servers"),z.get("/api/v1/servers")]);if(n(r||[]),u(E||[]),$){const X=(r||[]).find(ge=>ge.id===$.id)||null;M(X)}if(_){const X=(r||[]).find(ge=>ge.id===_.id)||null;I(X)}}catch(r){console.error(r);const E=r instanceof Y?r.message:"Failed to load node pools or servers";j(E)}finally{t(!1)}}c.useEffect(()=>{F()},[]);const o=c.useMemo(()=>{const r=b.trim().toLowerCase();return r?a.filter(E=>E.name.toLowerCase().includes(r)||(E.servers||[]).some(X=>(X.hostname||"").toLowerCase().includes(r)||(X.ip||X.ip_address||"").toLowerCase().includes(r)||(X.role||"").toLowerCase().includes(r))):a},[a,b]);async function d(r){confirm("Delete this node pool? This cannot be undone.")&&(await z.delete(`/api/v1/node-pools/${r}`),await F())}const l=B({resolver:K(Or),defaultValues:{name:"",server_ids:[]}}),v=async r=>{const E={name:r.name.trim()};r.server_ids&&r.server_ids.length>0&&(E.server_ids=r.server_ids),await z.post("/api/v1/node-pools",E),p(!1),l.reset({name:"",server_ids:[]}),await F()},A=B({resolver:K(Lr),defaultValues:{name:""}});function H(r){I(r),A.reset({name:r.name})}const V=async r=>{_&&(await z.patch(`/api/v1/node-pools/${_.id}`,{name:r.name.trim()}),I(null),await F())},Q=B({resolver:K(Ar),defaultValues:{server_ids:[]}});function U(r){M(r),Q.reset({server_ids:[]})}const ye=async r=>{$&&(await z.post(`/api/v1/node-pools/${$.id}/servers`,{server_ids:r.server_ids}),Q.reset({server_ids:[]}),await F())};async function xe(r){$&&confirm("Detach this server from the pool?")&&(await z.delete(`/api/v1/node-pools/${$.id}/servers/${r}`),await F())}const i=c.useMemo(()=>{if(!$)return[];const r=new Set(($.servers||[]).map(E=>E.id));return m.filter(E=>!r.has(E.id))},[$,m]);return s?e.jsx("div",{className:"p-6",children:"Loading node pools…"}):g?e.jsx("div",{className:"p-6 text-red-500",children:g}):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(Rs,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(L,{value:b,onChange:r=>f(r.target.value),placeholder:"Search pools or servers…",className:"w-72 pl-8"})]}),e.jsxs(x,{variant:"outline",onClick:F,children:[e.jsx(Vs,{className:"mr-2 h-4 w-4"})," Refresh"]}),e.jsxs(ae,{open:k,onOpenChange:p,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{onClick:()=>p(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"})," Create Pool"]})}),e.jsxs(re,{className:"sm:max-w-lg",children:[e.jsx(ne,{children:e.jsx(le,{children:"Create node pool"})}),e.jsx(G,{...l,children:e.jsxs("form",{onSubmit:l.handleSubmit(v),className:"space-y-4",children:[e.jsx(w,{control:l.control,name:"name",render:({field:r})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{placeholder:"pool-workers-a",...r})}),e.jsx(S,{})]})}),e.jsx(w,{control:l.control,name:"server_ids",render:({field:r})=>e.jsxs(y,{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:[m.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No servers available"}),m.map(E=>{const X=r.value?.includes(E.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(Ss,{checked:X,onCheckedChange:ge=>{const pe=new Set(r.value||[]);ge===!0?pe.add(E.id):pe.delete(E.id),r.onChange(Array.from(pe))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:ks(E)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:Ke(E.id,8)})]})]},E.id)})]}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:l.formState.isSubmitting,children:l.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(De,{children:[e.jsx(Te,{children:e.jsxs(W,{children:[e.jsx(P,{children:"Name"}),e.jsx(P,{children:"Servers"}),e.jsx(P,{children:"Annotations"}),e.jsx(P,{children:"Labels"}),e.jsx(P,{children:"Taints"}),e.jsx(P,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs($e,{children:[o.map(r=>e.jsxs(W,{children:[e.jsx(D,{className:"font-medium",children:r.name}),e.jsxs(D,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(r.servers||[]).slice(0,6).map(E=>e.jsxs(Be,{variant:"secondary",className:"gap-1",children:[e.jsx(Fs,{className:"h-3 w-3"})," ",E.hostname||E.ip||E.ip_address||Ke(E.id,6),E.status&&e.jsx("span",{className:"ml-1",children:e.jsx(Cs,{status:E.status})})]},E.id)),(r.servers||[]).length===0&&e.jsx("span",{className:"text-muted-foreground",children:"No servers"}),(r.servers||[]).length>6&&e.jsxs("span",{className:"text-muted-foreground",children:["+",(r.servers||[]).length-6," more"]})]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>U(r),children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," Manage servers"]})]}),e.jsxs(D,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Annotations"}),e.jsxs(x,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," Manage Annotations"]})]}),e.jsxs(D,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Labels"}),e.jsxs(x,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," Manage Labels"]})]}),e.jsxs(D,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Taints"}),e.jsxs(x,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," Manage Taints"]})]}),e.jsx(D,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>H(r),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(Re,{children:[e.jsx(Ve,{asChild:!0,children:e.jsxs(x,{variant:"destructive",size:"sm",children:[e.jsx(we,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(He,{align:"end",children:e.jsx(me,{onClick:()=>d(r.id),children:"Confirm delete"})})]})]})})]},r.id)),o.length===0&&e.jsx(W,{children:e.jsx(D,{colSpan:3,className:"text-muted-foreground py-10 text-center",children:"No node pools match your search."})})]})]})})}),e.jsx(ae,{open:!!_,onOpenChange:r=>!r&&I(null),children:e.jsxs(re,{className:"sm:max-w-md",children:[e.jsx(ne,{children:e.jsx(le,{children:"Edit node pool"})}),e.jsx(G,{...A,children:e.jsxs("form",{onSubmit:A.handleSubmit(V),className:"space-y-4",children:[e.jsx(w,{control:A.control,name:"name",render:({field:r})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{placeholder:"pool-workers-a",...r})}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>I(null),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:A.formState.isSubmitting,children:A.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(ae,{open:!!$,onOpenChange:r=>!r&&M(null),children:e.jsxs(re,{className:"sm:max-w-2xl",children:[e.jsx(ne,{children:e.jsxs(le,{children:["Manage servers 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 servers"}),e.jsx("div",{className:"overflow-hidden rounded-xl border",children:e.jsxs(De,{children:[e.jsx(Te,{children:e.jsxs(W,{children:[e.jsx(P,{children:"Server"}),e.jsx(P,{children:"IP"}),e.jsx(P,{children:"Role"}),e.jsx(P,{children:"Status"}),e.jsx(P,{className:"w-[120px] text-right",children:"Detach"})]})}),e.jsxs($e,{children:[($?.servers||[]).map(r=>e.jsxs(W,{children:[e.jsx(D,{className:"font-medium",children:r.hostname||Ke(r.id,8)}),e.jsx(D,{children:e.jsx("code",{className:"font-mono text-sm",children:r.ip||r.ip_address||"—"})}),e.jsx(D,{className:"capitalize",children:r.role||"—"}),e.jsx(D,{children:e.jsx(Cs,{status:r.status})}),e.jsx(D,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(x,{variant:"destructive",size:"sm",onClick:()=>xe(r.id),children:[e.jsx(xa,{className:"mr-2 h-4 w-4"})," Detach"]})})})]},r.id)),($?.servers||[]).length===0&&e.jsx(W,{children:e.jsx(D,{colSpan:5,className:"text-muted-foreground py-8 text-center",children:"No servers attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(G,{...Q,children:e.jsxs("form",{onSubmit:Q.handleSubmit(ye),className:"space-y-3",children:[e.jsx(w,{control:Q.control,name:"server_ids",render:({field:r})=>e.jsxs(y,{children:[e.jsx(N,{children:"Attach more servers"}),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:[i.length===0&&e.jsx("div",{className:"text-muted-foreground p-2 text-sm",children:"No more servers available to attach"}),i.map(E=>{const X=r.value?.includes(E.id)||!1;return e.jsxs("label",{className:"hover:bg-accent flex cursor-pointer items-start gap-2 rounded p-1",children:[e.jsx(Ss,{checked:X,onCheckedChange:ge=>{const pe=new Set(r.value||[]);ge===!0?pe.add(E.id):pe.delete(E.id),r.onChange(Array.from(pe))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"text-sm font-medium",children:ks(E)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:Ke(E.id,8)})]})]},E.id)})]}),e.jsx(S,{})]})}),e.jsx(ie,{className:"gap-2",children:e.jsxs(x,{type:"submit",disabled:Q.formState.isSubmitting,children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," ",Q.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})},_e=["pending","provisioning","ready","failed"],Ie=["master","worker","bastion"],Ys=J({hostname:R().trim().max(120,"Max 120 chars").optional(),ip_address:R().trim().min(1,"IP address is required"),role:Ne(Ie),ssh_key_id:ts("Pick a valid SSH key"),ssh_user:R().trim().min(1,"SSH user is required"),status:Ne(_e).default("pending")}),Tr=Ys.partial();function $r({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Be,{variant:t,className:"capitalize",children:s})}function Ze(s,t=16){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}${s.slice(-t)}`}const Mr=()=>{const[s,t]=c.useState([]),[a,n]=c.useState([]),[m,u]=c.useState(!1),[g,j]=c.useState(null),[b,f]=c.useState(""),[k,p]=c.useState(""),[_,I]=c.useState(""),[$,M]=c.useState(!1),[F,o]=c.useState(null);function d(){const i=new URLSearchParams;return k&&i.set("status",k),_&&i.set("role",_),`/api/v1/servers${i.toString()?`?${i.toString()}`:""}`}async function l(){u(!0),j(null);try{const[i,r]=await Promise.all([z.get(d()),z.get("/api/v1/ssh")]);t(i??[]),n(r??[])}catch(i){console.error(i),j("Failed to load servers or SSH keys")}finally{u(!1)}}c.useEffect(()=>{l();const i=r=>{r.key==="active_org_id"&&l()};return window.addEventListener("storage",i),()=>window.removeEventListener("storage",i)},[]),c.useEffect(()=>{l()},[k,_]);const v=c.useMemo(()=>{const i=new Map;return a.forEach(r=>i.set(r.id,r)),i},[a]),A=c.useMemo(()=>{const i=b.trim().toLowerCase();return i?s.filter(r=>(r.hostname??"").toLowerCase().includes(i)||r.ip_address.toLowerCase().includes(i)||r.role.toLowerCase().includes(i)||r.ssh_user.toLowerCase().includes(i)):s},[s,b]);async function H(i){confirm("Delete this server? This cannot be undone.")&&(await z.delete(`/api/v1/servers/${encodeURIComponent(i)}`),await l())}const V=B({resolver:K(Ys),defaultValues:{hostname:"",ip_address:"",role:"worker",ssh_key_id:"",ssh_user:"ubuntu",status:"pending"}}),Q=async i=>{const r={ip_address:i.ip_address.trim(),role:i.role,ssh_key_id:i.ssh_key_id,ssh_user:i.ssh_user.trim(),status:i.status};i.hostname&&i.hostname.trim()&&(r.hostname=i.hostname.trim()),await z.post("/api/v1/servers",r),M(!1),V.reset(),await l()},U=B({resolver:K(Tr),defaultValues:{}});function ye(i){o(i),U.reset({hostname:i.hostname??"",ip_address:i.ip_address,role:Ie.includes(i.role)?i.role:"worker",ssh_key_id:i.ssh_key_id,ssh_user:i.ssh_user,status:_e.includes(i.status)?i.status:"pending"})}const xe=async i=>{if(!F)return;const r={};i.hostname!==void 0&&(r.hostname=i.hostname?.trim()||""),i.ip_address!==void 0&&(r.ip_address=i.ip_address.trim()),i.role!==void 0&&(r.role=i.role),i.ssh_key_id!==void 0&&(r.ssh_key_id=i.ssh_key_id),i.ssh_user!==void 0&&(r.ssh_user=i.ssh_user.trim()),i.status!==void 0&&(r.status=i.status),await z.patch(`/api/v1/servers/${encodeURIComponent(F.id)}`,r),o(null),await l()};return m?e.jsx("div",{className:"p-6",children:"Loading servers…"}):g?e.jsx("div",{className:"p-6 text-red-500",children:g}):e.jsxs(Ye,{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(Rs,{className:"absolute top-2.5 left-2 h-4 w-4 opacity-60"}),e.jsx(L,{value:b,onChange:i=>f(i.target.value),placeholder:"Search hostname, IP, role, user…",className:"w-64 pl-8"})]}),e.jsxs(Z,{value:_,onValueChange:i=>I(i),children:[e.jsx(se,{className:"w-36",children:e.jsx(ee,{placeholder:"Role (all)"})}),e.jsx(te,{children:Ie.map(i=>e.jsx(q,{value:i,children:i},i))})]}),e.jsxs(Z,{value:k,onValueChange:i=>p(i),children:[e.jsx(se,{className:"w-40",children:e.jsx(ee,{placeholder:"Status (all)"})}),e.jsx(te,{children:_e.map(i=>e.jsx(q,{value:i,children:i},i))})]}),e.jsxs(x,{variant:"outline",onClick:l,children:[e.jsx(Vs,{className:"mr-2 h-4 w-4"}),"Refresh"]}),e.jsxs(ae,{open:$,onOpenChange:M,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{onClick:()=>M(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"Create Server"]})}),e.jsxs(re,{className:"sm:max-w-lg",children:[e.jsx(ne,{children:e.jsx(le,{children:"Create server"})}),e.jsx(G,{...V,children:e.jsxs("form",{onSubmit:V.handleSubmit(Q),className:"space-y-4",children:[e.jsx(w,{control:V.control,name:"hostname",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Hostname"}),e.jsx(C,{children:e.jsx(L,{placeholder:"worker-01",...i})}),e.jsx(S,{})]})}),e.jsx(w,{control:V.control,name:"ip_address",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"IP address"}),e.jsx(C,{children:e.jsx(L,{placeholder:"10.0.1.23",...i})}),e.jsx(S,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(w,{control:V.control,name:"role",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:"Select role"})})}),e.jsx(te,{children:Ie.map(r=>e.jsx(q,{value:r,children:r},r))})]}),e.jsx(S,{})]})}),e.jsx(w,{control:V.control,name:"ssh_user",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"SSH user"}),e.jsx(C,{children:e.jsx(L,{placeholder:"ubuntu",...i})}),e.jsx(S,{})]})})]}),e.jsx(w,{control:V.control,name:"ssh_key_id",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"SSH key"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:a.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(te,{children:a.map(r=>e.jsxs(q,{value:r.id,children:[r.name?r.name:"Unnamed key"," —"," ",Ze(r.fingerprint,8)]},r.id))})]}),e.jsx(S,{})]})}),e.jsx(w,{control:V.control,name:"status",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Initial status"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:"pending"})})}),e.jsx(te,{children:_e.map(r=>e.jsx(q,{value:r,children:r},r))})]}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsx(x,{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(De,{children:[e.jsx(Te,{children:e.jsxs(W,{children:[e.jsx(P,{children:"Hostname"}),e.jsx(P,{children:"IP address"}),e.jsx(P,{children:"Role"}),e.jsx(P,{children:"SSH user"}),e.jsx(P,{children:"SSH key"}),e.jsx(P,{children:"Status"}),e.jsx(P,{children:"Created"}),e.jsx(P,{className:"w-[180px] text-right",children:"Actions"})]})}),e.jsxs($e,{children:[A.map(i=>{const r=v.get(i.ssh_key_id);return e.jsxs(W,{children:[e.jsx(D,{className:"font-medium",children:i.hostname||"—"}),e.jsx(D,{children:e.jsx("code",{className:"font-mono text-sm",children:i.ip_address})}),e.jsx(D,{className:"capitalize",children:i.role}),e.jsx(D,{children:e.jsx("code",{className:"font-mono text-sm",children:i.ssh_user})}),e.jsx(D,{children:r?e.jsxs(ls,{children:[e.jsx(os,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Be,{variant:"secondary",children:r.name||"SSH key"}),e.jsx("code",{className:"font-mono text-xs",children:Ze(r.fingerprint,8)})]})}),e.jsx(ds,{className:"max-w-[70vw]",children:e.jsx("p",{className:"font-mono text-xs break-all",children:r.public_keys})})]}):e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})}),e.jsx(D,{children:e.jsx($r,{status:i.status})}),e.jsx(D,{children:new Date(i.created_at).toLocaleString()}),e.jsx(D,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>ye(i),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(Re,{children:[e.jsx(Ve,{asChild:!0,children:e.jsxs(x,{variant:"destructive",size:"sm",children:[e.jsx(we,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(He,{align:"end",children:e.jsx(me,{onClick:()=>H(i.id),children:"Confirm delete"})})]})]})})]},i.id)}),A.length===0&&e.jsx(W,{children:e.jsx(D,{colSpan:8,className:"text-muted-foreground py-10 text-center",children:"No servers match your filters."})})]})]})})})]}),e.jsx(ae,{open:!!F,onOpenChange:i=>!i&&o(null),children:e.jsxs(re,{className:"sm:max-w-lg",children:[e.jsx(ne,{children:e.jsx(le,{children:"Edit server"})}),e.jsx(G,{...U,children:e.jsxs("form",{onSubmit:U.handleSubmit(xe),className:"space-y-4",children:[e.jsx(w,{control:U.control,name:"hostname",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Hostname"}),e.jsx(C,{children:e.jsx(L,{placeholder:"worker-01",...i})}),e.jsx(S,{})]})}),e.jsx(w,{control:U.control,name:"ip_address",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"IP address"}),e.jsx(C,{children:e.jsx(L,{placeholder:"10.0.1.23",...i})}),e.jsx(S,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(w,{control:U.control,name:"role",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:"Select role"})})}),e.jsx(te,{children:Ie.map(r=>e.jsx(q,{value:r,children:r},r))})]}),e.jsx(S,{})]})}),e.jsx(w,{control:U.control,name:"ssh_user",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"SSH user"}),e.jsx(C,{children:e.jsx(L,{placeholder:"ubuntu",...i})}),e.jsx(S,{})]})})]}),e.jsx(w,{control:U.control,name:"ssh_key_id",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"SSH key"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:a.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(te,{children:a.map(r=>e.jsxs(q,{value:r.id,children:[r.name?r.name:"SSH key"," — ",Ze(r.fingerprint,8)]},r.id))})]}),e.jsx(S,{})]})}),e.jsx(w,{control:U.control,name:"status",render:({field:i})=>e.jsxs(y,{children:[e.jsx(N,{children:"Status"}),e.jsxs(Z,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(se,{children:e.jsx(ee,{placeholder:"pending"})})}),e.jsx(te,{children:_e.map(r=>e.jsx(q,{value:r,children:r},r))})]}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>o(null),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:U.formState.isSubmitting,children:U.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})},Pr=()=>e.jsx("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:"Taints"})})});function _s(){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 dont have access to this area."})]})}const Is=()=>{const s=Fe();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(x,{onClick:()=>s("/dashboard"),children:"Go back to Dashboard"})]})},Fr=J({name:R().min(1,"Name is required").max(100,"Max 100 characters"),comment:R().trim().max(100,"Max 100 characters").default(""),bits:Ne(["2048","3072","4096"])});function Rr(s,t="download.bin"){if(!s)return t;const a=/filename\*=UTF-8''([^;]+)/i.exec(s);return a?.[1]?decodeURIComponent(a[1]):/filename="?([^"]+)"?/i.exec(s)?.[1]??t}function Vr(s,t=24){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}${s.slice(-t)}`}function Hr(s){return s?.split(/\s+/)?.[0]??"ssh-key"}async function Ur(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 Br=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(null),[m,u]=c.useState(!0),[g,j]=c.useState(""),[b,f]=c.useState(!1),k=c.useMemo(()=>!!localStorage.getItem("active_org_id"),[]);async function p(){u(!0),n(null);try{if(!k){t([]),n("Select an organization first.");return}const o=await z.get("/api/v1/ssh");t(o??[])}catch(o){console.error(o),n("Failed to fetch SSH keys")}finally{u(!1)}}c.useEffect(()=>{p();const o=d=>{d.key==="active_org_id"&&p()};return window.addEventListener("storage",o),()=>window.removeEventListener("storage",o)},[]);const _=s.filter(o=>`${o.name} ${o.public_keys} ${o.fingerprint}`.toLowerCase().includes(g.toLowerCase()));async function I(o,d="both"){const l=localStorage.getItem("access_token"),v=localStorage.getItem("active_org_id"),A=`${Ge}/api/v1/ssh/${encodeURIComponent(o)}/download?part=${encodeURIComponent(d)}`;try{const H=await fetch(A,{method:"GET",headers:{...l?{Authorization:`Bearer ${l}`}:{},...v?{"X-Org-ID":v}:{}}});if(!H.ok){const i=await H.text().catch(()=>"");throw new Error(i||`HTTP ${H.status}`)}const V=await H.blob(),Q=d==="both"?`ssh_key_${o}.zip`:d==="public"?`id_rsa_${o}.pub`:`id_rsa_${o}.pem`,U=Rr(H.headers.get("content-disposition")??void 0,Q),ye=URL.createObjectURL(V),xe=document.createElement("a");xe.href=ye,xe.download=U,document.body.appendChild(xe),xe.click(),xe.remove(),URL.revokeObjectURL(ye)}catch(H){console.error(H),alert(H instanceof Error?H.message:"Download failed")}}async function $(o){try{await z.delete(`/api/v1/ssh/${encodeURIComponent(o)}`),await p()}catch(d){console.error(d),alert("Failed to delete key")}}const M=B({resolver:K(Fr),defaultValues:{name:"",comment:"deploy@autoglue",bits:"4096"}});async function F(o){try{await z.post("/api/v1/ssh",{bits:Number(o.bits),comment:o.comment?.trim()??"",name:o.name.trim(),download:"none"}),f(!1),M.reset(),await p()}catch(d){console.error(d),alert("Failed to create key")}}return m?e.jsx("div",{className:"p-6",children:"Loading SSH Keys…"}):a?e.jsx("div",{className:"p-6 text-red-500",children:a}):e.jsx(Ye,{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(L,{value:g,onChange:o=>j(o.target.value),placeholder:"Search by name, fingerprint or key"})}),e.jsxs(ae,{open:b,onOpenChange:f,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{onClick:()=>f(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"Create New Keypair"]})}),e.jsxs(re,{className:"sm:max-w-lg",children:[e.jsx(ne,{children:e.jsx(le,{children:"Create SSH Keypair"})}),e.jsx(G,{...M,children:e.jsxs("form",{onSubmit:M.handleSubmit(F),className:"space-y-4",children:[e.jsx(w,{control:M.control,name:"name",render:({field:o})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{placeholder:"e.g., CI deploy key",...o})}),e.jsx(S,{})]})}),e.jsx(w,{control:M.control,name:"comment",render:({field:o})=>e.jsxs(y,{children:[e.jsx(N,{children:"Comment"}),e.jsx(C,{children:e.jsx(L,{placeholder:"e.g., deploy@autoglue",...o})}),e.jsx(S,{})]})}),e.jsx(w,{control:M.control,name:"bits",render:({field:o})=>e.jsxs(y,{children:[e.jsx(N,{children:"Key size"}),e.jsx(C,{children:e.jsxs("select",{className:"bg-background w-full rounded-md border px-3 py-2 text-sm",value:o.value,onChange:o.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(S,{})]})}),e.jsxs(ie,{className:"gap-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>f(!1),children:"Cancel"}),e.jsx(x,{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(De,{children:[e.jsx(Te,{children:e.jsxs(W,{children:[e.jsx(P,{children:"Name"}),e.jsx(P,{className:"min-w-[360px]",children:"Public Key"}),e.jsx(P,{children:"Fingerprint"}),e.jsx(P,{children:"Created"}),e.jsx(P,{className:"w-[160px] text-right",children:"Actions"})]})}),e.jsx($e,{children:_.map(o=>{const d=Hr(o.public_keys),l=Vr(o.public_keys,18);return e.jsxs(W,{children:[e.jsx(D,{className:"align-top",children:o.name}),e.jsx(D,{className:"align-top",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Be,{variant:"secondary",className:"whitespace-nowrap",children:d}),e.jsxs(ls,{children:[e.jsx(os,{asChild:!0,children:e.jsx("code",{className:"font-mono text-sm break-all md:max-w-[48ch] md:truncate md:break-normal",children:l})}),e.jsx(ds,{className:"max-w-[70vw]",children:e.jsx("div",{className:"max-w-full",children:e.jsx("p",{className:"font-mono text-xs break-all",children:o.public_keys})})})]})]})}),e.jsx(D,{className:"align-top",children:e.jsx("code",{className:"font-mono text-sm",children:o.fingerprint})}),e.jsx(D,{className:"align-top",children:new Date(o.created_at).toLocaleString(void 0,{year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),e.jsx(D,{className:"align-top",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>Ur(o.public_keys),title:"Copy public key",children:[e.jsx(ha,{className:"mr-2 h-4 w-4"}),"Copy"]}),e.jsxs(Re,{children:[e.jsx(Ve,{asChild:!0,children:e.jsxs(x,{variant:"outline",size:"sm",children:[e.jsx(ja,{className:"mr-2 h-4 w-4"}),"Download"]})}),e.jsxs(He,{align:"end",children:[e.jsx(me,{onClick:()=>I(o.id,"both"),children:"Public + Private (.zip)"}),e.jsx(me,{onClick:()=>I(o.id,"public"),children:"Public only (.pub)"}),e.jsx(me,{onClick:()=>I(o.id,"private"),children:"Private only (.pem)"})]})]}),e.jsxs(x,{variant:"destructive",size:"sm",onClick:()=>$(o.id),children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"Delete"]})]})})]},o.id)})})]})})})]})})};function Kr(s){const t=s?.user_id??s?.UserID??s?.user?.id??s?.User?.ID??"",a=s?.email??s?.Email??s?.user?.email??s?.User?.Email,n=s?.name??s?.Name??s?.user?.name??s?.User?.Name,m=s?.role??s?.Role??"member",u=s?.created_at??s?.CreatedAt;return{userId:String(t),email:a,name:n,role:String(m),joinedAt:u}}const Gr=J({email:Se("Enter a valid email"),role:Ne(["member","admin"])}),qr=()=>{const[s,t]=c.useState(!0),[a,n]=c.useState([]),[m,u]=c.useState(null),[g,j]=c.useState(!1),[b,f]=c.useState(!1),[k,p]=c.useState(null),_=c.useMemo(()=>je(),[]),I=B({resolver:K(Gr),defaultValues:{email:"",role:"member"},mode:"onChange"});async function $(){try{const d=await z.get("/api/v1/auth/me");u(d)}catch{}}async function M(d){if(!d){n([]),t(!1);return}t(!0);try{const l=await z.get("/api/v1/orgs/members");n((l??[]).map(Kr))}catch(l){const v=l instanceof Y?l.message:"Failed to load members";O.error(v)}finally{t(!1)}}c.useEffect(()=>{$(),M(_)},[_]),c.useEffect(()=>{const d=()=>void M(je()),l=v=>{v.key==="active_org_id"&&d()};return window.addEventListener(be,d),window.addEventListener("storage",l),()=>{window.removeEventListener(be,d),window.removeEventListener("storage",l)}},[]);async function F(d){const l=je();if(!l){O.error("Select an organization first");return}try{f(!0),await z.post("/api/v1/orgs/invite",d),O.success(`Invited ${d.email}`),j(!1),I.reset({email:"",role:"member"}),M(l)}catch(v){const A=v instanceof Y?v.message:"Failed to invite member";O.error(A)}finally{f(!1)}}async function o(d){const l=je();if(!l){O.error("Select an organization first");return}try{p(d),await z.delete(`/api/v1/orgs/members/${d}`,{headers:{"X-Org-ID":l}}),n(v=>v.filter(A=>A.userId!==d)),O.success("Member removed")}catch(v){const A=v instanceof Y?v.message:"Failed to remove member";O.error(A)}finally{p(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(x,{disabled:!0,children:[e.jsx(bs,{className:"mr-2 h-4 w-4"}),"Invite"]})]}),e.jsx(ze,{}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((d,l)=>e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(fe,{className:"h-5 w-40"})}),e.jsxs(ce,{className:"space-y-2",children:[e.jsx(fe,{className:"h-4 w-56"}),e.jsx(fe,{className:"h-4 w-40"})]}),e.jsx(Ae,{children:e.jsx(fe,{className:"h-9 w-24"})})]},l))})]}):je()?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(ae,{open:g,onOpenChange:j,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{children:[e.jsx(bs,{className:"mr-2 h-4 w-4"}),"Invite"]})}),e.jsxs(re,{className:"sm:max-w-[520px]",children:[e.jsxs(ne,{children:[e.jsx(le,{children:"Invite member"}),e.jsx(qe,{children:"Send an invite to join this organization."})]}),e.jsx(G,{...I,children:e.jsxs("form",{onSubmit:I.handleSubmit(F),className:"grid gap-4 py-2",children:[e.jsx(w,{control:I.control,name:"email",render:({field:d})=>e.jsxs(y,{children:[e.jsx(N,{children:"Email"}),e.jsx(C,{children:e.jsx(L,{type:"email",placeholder:"jane@example.com",...d})}),e.jsx(S,{})]})}),e.jsx(w,{control:I.control,name:"role",render:({field:d})=>e.jsxs(y,{children:[e.jsx(N,{children:"Role"}),e.jsxs(Z,{onValueChange:d.onChange,defaultValue:d.value,children:[e.jsx(C,{children:e.jsx(se,{className:"w-[200px]",children:e.jsx(ee,{placeholder:"Select role"})})}),e.jsxs(te,{children:[e.jsx(q,{value:"member",children:"Member"}),e.jsx(q,{value:"admin",children:"Admin"})]})]}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(x,{type:"submit",disabled:!I.formState.isValid||b,children:b?"Sending…":"Send invite"})]})]})})]})]})]}),e.jsx(ze,{}),a.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:a.map(d=>{const l=m?.id&&d.userId===m.id;return e.jsxs(oe,{className:"flex flex-col",children:[e.jsx(de,{children:e.jsx(he,{className:"text-base",children:d.name||d.email||d.userId})}),e.jsxs(ce,{className:"text-muted-foreground space-y-1 text-sm",children:[d.email&&e.jsxs("div",{children:["Email: ",d.email]}),e.jsxs("div",{children:["Role: ",d.role]}),d.joinedAt&&e.jsxs("div",{children:["Joined: ",new Date(d.joinedAt).toLocaleString()]})]}),e.jsxs(Ae,{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(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(x,{variant:"destructive",disabled:l||k===d.userId,className:"ml-auto",children:[e.jsx(we,{className:"mr-2 h-5 w-5"}),k===d.userId?"Removing…":"Remove"]})}),e.jsxs(us,{children:[e.jsxs(xs,{children:[e.jsx(js,{children:"Remove member?"}),e.jsxs(fs,{children:["This will remove ",e.jsx("b",{children:d.name||d.email||d.userId})," from the organization."]})]}),e.jsxs(hs,{className:"sm:justify-between",children:[e.jsx(ps,{disabled:k===d.userId,children:"Cancel"}),e.jsx(gs,{asChild:!0,disabled:k===d.userId,children:e.jsx(x,{variant:"destructive",onClick:()=>o(d.userId),children:"Confirm remove"})})]})]})]})]})]},d.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(ze,{}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"No organization selected. Choose an organization to manage its members."})]})},Jr=J({name:R().min(2).max(100),slug:R().min(2).max(50).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Use lowercase letters, numbers, and hyphens.")}),Wr=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(!0),[m,u]=c.useState(!1),[g,j]=c.useState(null),[b,f]=c.useState(null),k=c.useRef(!1),p=B({resolver:K(Jr),mode:"onChange",defaultValues:{name:"",slug:""}}),_=p.watch("name");c.useEffect(()=>{k.current||p.setValue("slug",ws(_||""),{shouldValidate:!0})},[_,p]);const I=async()=>{n(!0);try{const o=await z.get("/api/v1/orgs");t(o),u(o.length===0)}catch(o){const d=o instanceof Y?o.message:"Failed to load organizations";O.error(d)}finally{n(!1)}};c.useEffect(()=>{j(je()),I();const o=v=>{v.key==="active_org_id"&&j(v.newValue)};window.addEventListener("storage",o);const d=v=>{const A=v.detail??null;j(A)};window.addEventListener(be,d);const l=()=>void I();return window.addEventListener(Le,l),()=>{window.removeEventListener("storage",o),window.removeEventListener(be,d),window.removeEventListener(Le,l)}},[]);async function $(o){try{const d=await z.post("/api/v1/orgs",o);t(l=>[d,...l]),Oe(d.id),j(d.id),ys(),O.success(`Created ${d.name}`),u(!1),p.reset({name:"",slug:""}),k.current=!1}catch(d){const l=d instanceof Y?d.message:"Failed to create organization";O.error(l)}}function M(o){Oe(o.id),j(o.id),O.success(`Switched to ${o.name}`)}async function F(o){try{f(o.id),await z.delete(`/api/v1/orgs/${o.id}`),t(d=>{const l=d.filter(v=>v.id!==o.id);if(g===o.id){const v=l[0]?.id??null;Oe(v),j(v)}return l}),ys(),O.success(`Deleted ${o.name}`)}catch(d){const l=d instanceof Y?d.message:"Failed to delete organization";O.error(l)}finally{f(null)}}return a?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((o,d)=>e.jsxs(oe,{children:[e.jsx(de,{children:e.jsx(fe,{className:"h-5 w-40"})}),e.jsxs(ce,{children:[e.jsx(fe,{className:"mb-2 h-4 w-24"}),e.jsx(fe,{className:"h-4 w-48"})]}),e.jsx(Ae,{children:e.jsx(fe,{className:"h-9 w-24"})})]},d))})]}):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(x,{onClick:()=>u(!0),children:"New organization"})]}),e.jsx(ze,{}),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(o=>e.jsxs(oe,{className:"flex flex-col",children:[e.jsx(de,{children:e.jsx(he,{className:"text-base",children:o.name})}),e.jsxs(ce,{className:"text-muted-foreground text-sm",children:[e.jsxs("div",{children:["Slug: ",o.slug]}),e.jsxs("div",{className:"mt-1",children:["ID: ",o.id]})]}),e.jsxs(Ae,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(x,{onClick:()=>M(o),children:o.id===g?"Selected":"Select"}),e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(x,{variant:"destructive",className:"ml-auto",disabled:b===o.id,children:[e.jsx(we,{className:"mr-2 h-5 w-5"}),b===o.id?"Deleting…":"Delete"]})}),e.jsxs(us,{children:[e.jsxs(xs,{children:[e.jsx(js,{children:"Delete organization?"}),e.jsxs(fs,{children:["This will permanently delete ",e.jsx("b",{children:o.name}),". This action cannot be undone."]})]}),e.jsxs(hs,{className:"sm:justify-between",children:[e.jsx(ps,{disabled:b===o.id,children:"Cancel"}),e.jsx(gs,{asChild:!0,disabled:b===o.id,children:e.jsx(x,{variant:"destructive",onClick:()=>F(o),children:"Confirm delete"})})]})]})]})]})]},o.id))}),e.jsx(ae,{open:m,onOpenChange:u,children:e.jsxs(re,{className:"sm:max-w-[480px]",children:[e.jsxs(ne,{children:[e.jsx(le,{children:"Create organization"}),e.jsx(qe,{children:"Set a name and a URL-friendly slug."})]}),e.jsx(G,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit($),className:"space-y-4",children:[e.jsx(w,{control:p.control,name:"name",render:({field:o})=>e.jsxs(y,{children:[e.jsx(N,{children:"Name"}),e.jsx(C,{children:e.jsx(L,{placeholder:"Acme Inc",autoFocus:!0,...o})}),e.jsx(Ns,{children:"This is your organizations display name."}),e.jsx(S,{})]})}),e.jsx(w,{control:p.control,name:"slug",render:({field:o})=>e.jsxs(y,{children:[e.jsx(N,{children:"Slug"}),e.jsx(C,{children:e.jsx(L,{placeholder:"acme-inc",...o,onChange:d=>{k.current=!0,o.onChange(d)},onBlur:d=>{const l=ws(d.target.value);p.setValue("slug",l,{shouldValidate:!0}),o.onBlur()}})}),e.jsx(Ns,{children:"Lowercase, numbers and hyphens only."}),e.jsx(S,{})]})}),e.jsxs(ie,{className:"flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>{p.reset(),u(!1),k.current=!1},children:"Cancel"}),e.jsx(x,{type:"submit",disabled:!p.formState.isValid||p.formState.isSubmitting,children:p.formState.isSubmitting?"Creating...":"Create"})]})]})})]})})]})};function Yr(){return e.jsxs(fa,{children:[e.jsx(T,{path:"/",element:e.jsx(ns,{to:"/auth/login",replace:!0})}),e.jsxs(T,{path:"/auth",children:[e.jsx(T,{path:"login",element:e.jsx(vr,{})}),e.jsx(T,{path:"register",element:e.jsx(yr,{})}),e.jsx(T,{path:"forgot",element:e.jsx(gr,{})}),e.jsx(T,{path:"reset",element:e.jsx(Sr,{})}),e.jsx(T,{path:"verify",element:e.jsx(Cr,{})})]}),e.jsx(T,{element:e.jsx(rr,{}),children:e.jsxs(T,{element:e.jsx(ar,{}),children:[e.jsx(T,{element:e.jsx(nr,{}),children:e.jsx(T,{path:"/admin",children:e.jsx(T,{path:"users",element:e.jsx(jr,{})})})}),e.jsxs(T,{path:"/core",children:[e.jsx(T,{path:"annotations",element:e.jsx(kr,{})}),e.jsx(T,{path:"clusters",element:e.jsx(_r,{})}),e.jsx(T,{path:"labels",element:e.jsx(Er,{})}),e.jsx(T,{path:"nodepools",element:e.jsx(Dr,{})}),e.jsx(T,{path:"servers",element:e.jsx(Mr,{})}),e.jsx(T,{path:"taints",element:e.jsx(Pr,{})})]}),e.jsx(T,{path:"/security",children:e.jsx(T,{path:"ssh",element:e.jsx(Br,{})})}),e.jsxs(T,{path:"/settings",children:[e.jsx(T,{path:"orgs",element:e.jsx(Wr,{})}),e.jsx(T,{path:"members",element:e.jsx(qr,{})}),e.jsx(T,{path:"me",element:e.jsx(br,{})})]}),e.jsx(T,{path:"/403",element:e.jsx(_s,{})}),e.jsx(T,{path:"*",element:e.jsx(Is,{})})]})}),e.jsx(T,{path:"/403",element:e.jsx(_s,{})}),e.jsx(T,{path:"*",element:e.jsx(Is,{})})]})}const Xr=({...s})=>{const{theme:t="system"}=Es();return e.jsx(rt,{theme:t,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...s})};function Qr({children:s,defaultTheme:t="system",storageKey:a="vite-ui-theme"}){return e.jsx(nt,{attribute:"class",defaultTheme:t,enableSystem:!0,storageKey:a,disableTransitionOnChange:!0,children:s})}it.createRoot(document.getElementById("root")).render(e.jsx(c.StrictMode,{children:e.jsx(ga,{children:e.jsxs(Qr,{defaultTheme:"system",storageKey:"dragon-theme",children:[e.jsx(Yr,{}),e.jsx(Xr,{richColors:!0,position:"top-right"})]})})}));