mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 12:50:05 +01:00
2 lines
90 KiB
JavaScript
2 lines
90 KiB
JavaScript
import{t as Xs,m as Qs,r as c,j as e,n as es,z as Es,F as Zs,C as et,p as st,q as tt,v as W,w as V,_ as ye,x as Ne,y as at,A as q,B as G,D as O,E as ss,G as zs,T as rt,J as nt,H as it}from"./vendor-DBKlM1wc.js";import{S as Le,R as ot,a as Os,C as As,b as Ds,T as Ls,D as Ts,P as $s,O as Ms,c as lt,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 At,z as Dt,B as Lt,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 qt,U as Gt}from"./radix-BnAuhYuH.js";import{X as Ps,S as Kt,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 oa,U as vs,h as la,i as da,j as ca,k as ts,l as ma,m as ua,P as Ge,n as as,o as Se,p as Rs,R as Vs,q as xa,r as ha,s as bs,t as Ce,u as ja}from"./icons-CNkJtX2d.js";import{u as Ke,L as ve,O as rs,N as ns,a as Te,b as Hs,R as fa,c as M,B as ga}from"./router-CQ4G2GmP.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 f of u.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&n(f)}).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 x(...s){return Xs(Qs(s))}function ws(s){return s.toLowerCase().trim().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)+/g,"")}const Xe=768;function pa(){const[s,t]=c.useState(void 0);return c.useEffect(()=>{const a=window.matchMedia(`(max-width: ${Xe-1}px)`),n=()=>{t(window.innerWidth<Xe)};return a.addEventListener("change",n),t(window.innerWidth<Xe),()=>a.removeEventListener("change",n)},[]),!!s}const is=es("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function h({className:s,variant:t,size:a,asChild:n=!1,...m}){const u=n?Le:"button";return e.jsx(u,{"data-slot":"button",className:x(is({variant:t,size:a,className:s})),...m})}function D({className:s,type:t,...a}){return e.jsx("input",{type:t,"data-slot":"input",className:x("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(ot,{"data-slot":"separator",decorative:a,orientation:t,className:x("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:x("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(As,{"data-slot":"sheet-content",className:x("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(Ds,{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:x("flex flex-col gap-1.5 p-4",s),...t})}function Sa({className:s,...t}){return e.jsx(Ls,{"data-slot":"sheet-title",className:x("text-foreground font-semibold",s),...t})}function Ca({className:s,...t}){return e.jsx(Ts,{"data-slot":"sheet-description",className:x("text-muted-foreground text-sm",s),...t})}function fe({className:s,...t}){return e.jsx("div",{"data-slot":"skeleton",className:x("bg-accent animate-pulse rounded-md",s),...t})}function Je({delayDuration:s=0,...t}){return e.jsx(lt,{"data-slot":"tooltip-provider",delayDuration:s,...t})}function os({...s}){return e.jsx(Je,{children:e.jsx(dt,{"data-slot":"tooltip",...s})})}function ls({...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:x("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 Aa({defaultOpen:s=!0,open:t,onOpenChange:a,className:n,style:m,children:u,...f}){const j=pa(),[N,g]=c.useState(!1),[k,E]=c.useState(s),_=t??k,S=c.useCallback(l=>{const d=typeof l=="function"?l(_):l;a?a(d):E(d),document.cookie=`${ka}=${d}; path=/; max-age=${_a}`},[a,_]),L=c.useCallback(()=>j?g(l=>!l):S(l=>!l),[j,S,g]);c.useEffect(()=>{const l=d=>{d.key===Oa&&(d.metaKey||d.ctrlKey)&&(d.preventDefault(),L())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[L]);const T=_?"expanded":"collapsed",F=c.useMemo(()=>({state:T,open:_,setOpen:S,isMobile:j,openMobile:N,setOpenMobile:g,toggleSidebar:L}),[T,_,S,j,N,g,L]);return e.jsx(Us.Provider,{value:F,children:e.jsx(Je,{delayDuration:0,children:e.jsx("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":Ia,"--sidebar-width-icon":za,...m},className:x("group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",n),...f,children:u})})})}function Da({side:s="left",variant:t="sidebar",collapsible:a="offcanvas",className:n,children:m,...u}){const{isMobile:f,state:j,openMobile:N,setOpenMobile:g}=Bs();return a==="none"?e.jsx("div",{"data-slot":"sidebar",className:x("bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",n),...u,children:m}):f?e.jsx(va,{open:N,onOpenChange:g,...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:x("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:x("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 La({className:s,...t}){return e.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:x("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:x("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:x("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:x("relative flex w-full min-w-0 flex-col p-2",s),...t})}function Pa({className:s,asChild:t=!1,...a}){const n=t?Le:"div";return e.jsx(n,{"data-slot":"sidebar-group-label","data-sidebar":"group-label",className:x("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:x("w-full text-sm",s),...t})}function Ra({className:s,...t}){return e.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:x("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:x("group/menu-item relative",s),...t})}const Ha=es("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,...f}){const j=s?Le:"button",{isMobile:N,state:g}=Bs(),k=e.jsx(j,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":n,"data-active":t,className:x(Ha({variant:a,size:n}),u),...f});return m?(typeof m=="string"&&(m={children:m}),e.jsxs(os,{children:[e.jsx(ls,{asChild:!0,children:k}),e.jsx(ds,{side:"right",align:"center",hidden:g!=="collapsed"||N,...m})]})):k}const Ve="";class J 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 qa(){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?{}:qa(),...Ga(),...Ba(n.headers)},f=await fetch(`${Ve}${s}`,{method:t,headers:u,body:a===void 0?void 0:JSON.stringify(a),...n}),N=(f.headers.get("content-type")||"").includes("application/json"),g=N?await f.json().catch(()=>{}):await f.text().catch(()=>"");if(!f.ok){const k=N&&g&&typeof g=="object"&&"error"in g&&g.error||N&&g&&typeof g=="object"&&"message"in g&&g.message||typeof g=="string"&&g||`HTTP ${f.status}`;throw new J(f.status,String(k),g)}return console.debug("API ->",t,`${Ve}${s}`,u),N?g: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 Ka(s){return s&&(s.user||s.user_id)}function qs(s){return Ka(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(`${Ve}/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 $e({...s}){return e.jsx(gt,{"data-slot":"dropdown-menu",...s})}function Me({...s}){return e.jsx(pt,{"data-slot":"dropdown-menu-trigger",...s})}function Pe({className:s,sideOffset:t=4,...a}){return e.jsx(vt,{children:e.jsx(bt,{"data-slot":"dropdown-menu-content",sideOffset:t,className:x("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 ie({className:s,inset:t,variant:a="default",...n}){return e.jsx(wt,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":a,className:x("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($e,{children:[e.jsx(Me,{asChild:!0,children:e.jsx(h,{variant:"outline",size:"icon","aria-label":"Toggle theme",children:t==="light"?e.jsx(Kt,{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(Pe,{align:"end",children:[e.jsxs(ie,{onClick:()=>s("light"),children:[t==="light"&&e.jsx(Ee,{}),"Light"]}),e.jsxs(ie,{onClick:()=>s("dark"),children:[t==="dark"&&e.jsx(Ee,{}),"Dark"]}),e.jsxs(ie,{onClick:()=>s("system"),children:[t==="system"&&e.jsx(Ee,{}),"System"]})]})]})}const Ze="active_org_id",be="active-org-changed",Ae="orgs-changed";function je(){return localStorage.getItem(Ze)}function Oe(s){s?localStorage.setItem(Ze,s):localStorage.removeItem(Ze),window.dispatchEvent(new CustomEvent(be,{detail:s}))}function ys(){window.dispatchEvent(new Event(Ae))}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 N=j instanceof J?j.message:"Failed to load organizations";console.error(N)}}c.useEffect(()=>{n(je()),m();const j=k=>{k.key==="active_org_id"&&n(k.newValue)};window.addEventListener("storage",j);const N=k=>n(k.detail??null),g=()=>void m();return window.addEventListener(be,N),window.addEventListener(Ae,g),()=>{window.removeEventListener("storage",j),window.removeEventListener(be,N),window.removeEventListener(Ae,g)}},[]);const u=j=>{Oe(j),n(j)},f=s.find(j=>j.id===a)?.name??"Select Org";return e.jsxs($e,{children:[e.jsx(Me,{asChild:!0,children:e.jsx(h,{variant:"outline",className:"w-full justify-start",children:f})}),e.jsx(Pe,{className:"w-48",children:s.length===0?e.jsx(ie,{disabled:!0,children:"No organizations"}):s.map(j=>e.jsx(ie,{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/cluster",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:oa},{label:"Members",to:"/settings/members",icon:vs},{label:"Profile",to:"/settings/me",icon:la}]},{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 Ks=({item:s})=>{const t=Ke(),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(ts,{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(Ks,{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 f=await ue.me();if(!u)return;t(f)}catch{}finally{n(!1)}})(),()=>{u=!1}},[]);const m=c.useMemo(()=>{const u=qs(s),f=Ja(s);return Gs(er,u,f)},[s]);return a?e.jsx("div",{className:"p-6",children:"Loading…"}):e.jsxs(Da,{children:[e.jsx(La,{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,f)=>e.jsx(Ks,{item:u},f))}),e.jsxs(Ta,{className:"space-y-2 p-4",children:[e.jsx(Za,{}),e.jsx(Qa,{}),e.jsx(h,{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(Aa,{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=Ke();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=Ke();return c.useEffect(()=>{let f=!0;return(async()=>{try{const j=await ue.me();if(!f)return;m(qs(j))}catch{if(!f)return;m(!1)}finally{if(a(!1),!f)return}})(),()=>{f=!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 or({className:s,...t}){return e.jsx(zt,{"data-slot":"alert-dialog-overlay",className:x("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(or,{}),e.jsx(St,{"data-slot":"alert-dialog-content",className:x("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:x("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:x("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:x("text-lg font-semibold",s),...t})}function fs({className:s,...t}){return e.jsx(kt,{"data-slot":"alert-dialog-description",className:x("text-muted-foreground text-sm",s),...t})}function gs({className:s,...t}){return e.jsx(It,{className:x(is(),s),...t})}function ps({className:s,...t}){return e.jsx(_t,{className:x(is({variant:"outline"}),s),...t})}function ae({className:s,...t}){return e.jsx("div",{"data-slot":"card",className:x("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",s),...t})}function re({className:s,...t}){return e.jsx("div",{"data-slot":"card-header",className:x("@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:x("leading-none font-semibold",s),...t})}function ne({className:s,...t}){return e.jsx("div",{"data-slot":"card-content",className:x("px-6",s),...t})}function De({className:s,...t}){return e.jsx("div",{"data-slot":"card-footer",className:x("flex items-center px-6 [.border-t]:pt-6",s),...t})}function oe({...s}){return e.jsx(Os,{"data-slot":"dialog",...s})}function We({...s}){return e.jsx(Ot,{"data-slot":"dialog-trigger",...s})}function lr({...s}){return e.jsx($s,{"data-slot":"dialog-portal",...s})}function dr({className:s,...t}){return e.jsx(Ms,{"data-slot":"dialog-overlay",className:x("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 le({className:s,children:t,showCloseButton:a=!0,...n}){return e.jsxs(lr,{"data-slot":"dialog-portal",children:[e.jsx(dr,{}),e.jsxs(As,{"data-slot":"dialog-content",className:x("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(Ds,{"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 de({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-header",className:x("flex flex-col gap-2 text-center sm:text-left",s),...t})}function ce({className:s,...t}){return e.jsx("div",{"data-slot":"dialog-footer",className:x("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...t})}function me({className:s,...t}){return e.jsx(Ls,{"data-slot":"dialog-title",className:x("text-lg leading-none font-semibold",s),...t})}function He({className:s,...t}){return e.jsx(Ts,{"data-slot":"dialog-description",className:x("text-muted-foreground text-sm",s),...t})}function cr({className:s,...t}){return e.jsx(At,{"data-slot":"label",className:x("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 K=Zs,Js=c.createContext({}),v=({...s})=>e.jsx(Js.Provider,{value:{name:s.name},children:e.jsx(et,{...s})}),Ye=()=>{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 b({className:s,...t}){const a=c.useId();return e.jsx(Ws.Provider,{value:{id:a},children:e.jsx("div",{"data-slot":"form-item",className:x("grid gap-2",s),...t})})}function w({className:s,...t}){const{error:a,formItemId:n}=Ye();return e.jsx(cr,{"data-slot":"form-label","data-error":!!a,className:x("data-[error=true]:text-destructive",s),htmlFor:n,...t})}function C({...s}){const{error:t,formItemId:a,formDescriptionId:n,formMessageId:m}=Ye();return e.jsx(Le,{"data-slot":"form-control",id:a,"aria-describedby":t?`${n} ${m}`:`${n}`,"aria-invalid":!!t,...s})}function Ns({className:s,...t}){const{formDescriptionId:a}=Ye();return e.jsx("p",{"data-slot":"form-description",id:a,className:x("text-muted-foreground text-sm",s),...t})}function y({className:s,...t}){const{error:a,formMessageId:n}=Ye(),m=a?String(a?.message??""):t.children;return m?e.jsx("p",{"data-slot":"form-message",id:n,className:x("text-destructive text-sm",s),...t,children:m}):null}function Q({...s}){return e.jsx(Dt,{"data-slot":"select",...s})}function Z({...s}){return e.jsx($t,{"data-slot":"select-value",...s})}function ee({className:s,size:t="default",children:a,...n}){return e.jsxs(Lt,{"data-slot":"select-trigger","data-size":t,className:x("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(ts,{className:"size-4 opacity-50"})})]})}function se({className:s,children:t,position:a="popper",...n}){return e.jsx(Mt,{children:e.jsxs(Pt,{"data-slot":"select-content",className:x("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:x("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 B({className:s,children:t,...a}){return e.jsxs(Rt,{"data-slot":"select-item",className:x("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:x("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:x("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(ts,{className:"size-4"})})}const xr=W({name:V().min(1,"Name required"),email:Ne("Enter a valid email"),role:ye(["user","admin"]),password:V().min(8,"Min 8 characters")}),hr=W({name:V().min(1,"Name required"),email:Ne("Enter a valid email"),role:ye(["user","admin"]),password:V().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),[f,j]=c.useState(!1),[N,g]=c.useState(null),[k,E]=c.useState(null),_=q({resolver:G(xr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}}),S=q({resolver:G(hr),mode:"onChange",defaultValues:{name:"",email:"",role:"user",password:""}});async function L(){n(!0);try{const o=await z.get("/api/v1/admin/users?page=1&page_size=100");t(o.users??[])}catch(o){O.error(o instanceof J?o.message:"Failed to load users")}finally{n(!1)}}c.useEffect(()=>{L()},[]);async function T(o){try{const p=await z.post("/api/v1/admin/users",o);t(A=>[p,...A]),u(!1),_.reset({name:"",email:"",role:"user",password:""}),O.success(`Created ${p.email}`)}catch(p){O.error(p instanceof J?p.message:"Failed to create user")}}function F(o){g(o),S.reset({name:o.name||"",email:o.email,role:o.role??"user",password:""}),j(!0)}async function l(o){if(!N)return;const p={name:o.name,email:o.email,role:o.role};o.password&&o.password.length>=8&&(p.password=o.password);try{const A=await z.patch(`/api/v1/admin/users/${N.id}`,p);t(H=>H.map(R=>R.id===A.id?A:R)),j(!1),g(null),O.success(`Updated ${A.email}`)}catch(A){O.error(A instanceof J?A.message:"Failed to update user")}}async function d(o){try{E(o),await z.delete(`/api/v1/admin/users/${o}`),t(p=>p.filter(A=>A.id!==o)),O.success("User deleted")}catch(p){O.error(p instanceof J?p.message:"Failed to delete user")}finally{E(null)}}return e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Users"}),e.jsxs(h,{onClick:()=>u(!0),children:[e.jsx(Ge,{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(o=>e.jsxs(ae,{className:"flex flex-col",children:[e.jsx(re,{children:e.jsx(he,{className:"text-base",children:o.name||o.email})}),e.jsxs(ne,{className:"text-muted-foreground space-y-1 text-sm",children:[e.jsxs("div",{children:["Email: ",o.email]}),e.jsxs("div",{children:["Role: ",o.role]}),e.jsxs("div",{children:["Verified: ",o.email_verified?"Yes":"No"]}),e.jsxs("div",{children:["Joined: ",new Date(o.created_at).toLocaleString()]})]}),e.jsxs(De,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(h,{variant:"outline",onClick:()=>F(o),children:[e.jsx(as,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(h,{variant:"destructive",disabled:k===o.id,children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),k===o.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:o.email}),"."]})]}),e.jsxs(hs,{className:"sm:justify-between",children:[e.jsx(ps,{disabled:k===o.id,children:"Cancel"}),e.jsx(gs,{asChild:!0,disabled:k===o.id,children:e.jsx(h,{variant:"destructive",onClick:()=>d(o.id),children:"Confirm delete"})})]})]})]})]})]},o.id))}),e.jsx(oe,{open:m,onOpenChange:u,children:e.jsxs(le,{className:"sm:max-w-[520px]",children:[e.jsxs(de,{children:[e.jsx(me,{children:"Create user"}),e.jsx(He,{children:"Add a new user account."})]}),e.jsx(K,{..._,children:e.jsxs("form",{onSubmit:_.handleSubmit(T),className:"grid gap-4 py-2",children:[e.jsx(v,{name:"name",control:_.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{...o,placeholder:"Jane Doe"})}),e.jsx(y,{})]})}),e.jsx(v,{name:"email",control:_.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{type:"email",...o,placeholder:"jane@example.com"})}),e.jsx(y,{})]})}),e.jsx(v,{name:"role",control:_.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Role"}),e.jsxs(Q,{value:o.value,onValueChange:o.onChange,children:[e.jsx(C,{children:e.jsx(ee,{className:"w-[200px]",children:e.jsx(Z,{placeholder:"Select role"})})}),e.jsxs(se,{children:[e.jsx(B,{value:"user",children:"User"}),e.jsx(B,{value:"admin",children:"Admin"})]})]}),e.jsx(y,{})]})}),e.jsx(v,{name:"password",control:_.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Password"}),e.jsx(C,{children:e.jsx(D,{type:"password",...o,placeholder:"••••••••"})}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!_.formState.isValid||_.formState.isSubmitting,children:_.formState.isSubmitting?"Creating…":"Create"})]})]})})]})}),e.jsx(oe,{open:f,onOpenChange:j,children:e.jsxs(le,{className:"sm:max-w-[520px]",children:[e.jsxs(de,{children:[e.jsx(me,{children:"Edit user"}),e.jsx(He,{children:"Update user details. Leave password blank to keep it unchanged."})]}),e.jsx(K,{...S,children:e.jsxs("form",{onSubmit:S.handleSubmit(l),className:"grid gap-4 py-2",children:[e.jsx(v,{name:"name",control:S.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{...o})}),e.jsx(y,{})]})}),e.jsx(v,{name:"email",control:S.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{type:"email",...o})}),e.jsx(y,{})]})}),e.jsx(v,{name:"role",control:S.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"Role"}),e.jsxs(Q,{value:o.value,onValueChange:o.onChange,children:[e.jsx(C,{children:e.jsx(ee,{className:"w-[200px]",children:e.jsx(Z,{placeholder:"Select role"})})}),e.jsxs(se,{children:[e.jsx(B,{value:"user",children:"User"}),e.jsx(B,{value:"admin",children:"Admin"})]})]}),e.jsx(y,{})]})}),e.jsx(v,{name:"password",control:S.control,render:({field:o})=>e.jsxs(b,{children:[e.jsx(w,{children:"New password (optional)"}),e.jsx(C,{children:e.jsx(D,{type:"password",...o,placeholder:"Leave blank to keep"})}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!S.formState.isValid||S.formState.isSubmitting,children:S.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})}const fr=W({email:Ne()});function gr(){const s=q({resolver:G(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(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"Forgot password"})}),e.jsx(ne,{children:e.jsx(K,{...s,children:e.jsxs("form",{onSubmit:s.handleSubmit(t),className:"space-y-4",children:[e.jsx(v,{name:"email",control:s.control,render:({field:a})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{placeholder:"you@example.com",...a})}),e.jsx(y,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Send reset link"})]})})})]})})}const pr=W({email:Ne(),password:V().min(6)});function vr(){const s=Te(),t=Ke(),a=q({resolver:G(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(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"Sign in"})}),e.jsxs(ne,{children:[e.jsx(K,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(n),className:"space-y-4",children:[e.jsx(v,{name:"email",control:a.control,render:({field:m})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{placeholder:"you@example.com",...m})}),e.jsx(y,{})]})}),e.jsx(v,{name:"password",control:a.control,render:({field:m})=>e.jsxs(b,{children:[e.jsx(w,{children:"Password"}),e.jsx(C,{children:e.jsx(D,{type:"password",placeholder:"••••••••",...m})}),e.jsx(y,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Sign in"})]})}),e.jsxs("div",{className:"mt-4 flex justify-between text-sm",children:[e.jsx(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=Te();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(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"My Account"})}),e.jsxs(ne,{className:"space-y-3",children:[s?e.jsx("pre",{className:"bg-muted overflow-auto rounded p-3 text-sm",children:JSON.stringify(s,null,2)}):e.jsx("p",{children:"Loading…"}),e.jsx(h,{onClick:n,children:"Sign out"})]})]})})}const wr=W({name:V().min(2),email:Ne(),password:V().min(6)});function yr(){const s=Te(),t=q({resolver:G(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(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"Create account"})}),e.jsxs(ne,{children:[e.jsx(K,{...t,children:e.jsxs("form",{onSubmit:t.handleSubmit(a),className:"space-y-4",children:[e.jsx(v,{name:"name",control:t.control,render:({field:n})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{placeholder:"Jane Doe",...n})}),e.jsx(y,{})]})}),e.jsx(v,{name:"email",control:t.control,render:({field:n})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{placeholder:"you@example.com",...n})}),e.jsx(y,{})]})}),e.jsx(v,{name:"password",control:t.control,render:({field:n})=>e.jsxs(b,{children:[e.jsx(w,{children:"Password"}),e.jsx(C,{children:e.jsx(D,{type:"password",placeholder:"••••••••",...n})}),e.jsx(y,{})]})}),e.jsx(h,{type:"submit",className:"w-full",children:"Create account"})]})}),e.jsxs("div",{className:"mt-4 text-sm",children:["Already have an account?"," ",e.jsx(ve,{to:"/auth/login",className:"underline",children:"Sign in"})]})]})]})})}const Nr=W({new_password:V().min(6)});function Sr(){const[s]=Hs(),t=s.get("token"),a=q({resolver:G(Nr),defaultValues:{new_password:""}}),n=Te();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(f){O.error(f.message||"Reset failed")}}return e.jsx("div",{className:"mx-auto max-w-md",children:e.jsxs(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"Reset password"})}),e.jsxs(ne,{children:[e.jsx(K,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(m),className:"space-y-4",children:[e.jsx(v,{name:"new_password",control:a.control,render:({field:u})=>e.jsxs(b,{children:[e.jsx(w,{children:"New password"}),e.jsx(C,{children:e.jsx(D,{type:"password",placeholder:"••••••••",...u})}),e.jsx(y,{})]})}),e.jsx(h,{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(ae,{children:[e.jsx(re,{children:e.jsx(he,{children:"Email verification"})}),e.jsxs(ne,{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(h,{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(h,{asChild:!0,className:"mt-3",children:e.jsx(ve,{to:"/auth/login",children:"Back to sign in"})})]})]})]})})}const kr=es("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 Fe({className:s,variant:t,asChild:a=!1,...n}){const m=a?Le:"span";return e.jsx(m,{"data-slot":"badge",className:x(kr({variant:t}),s),...n})}function Ue({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:x("w-full caption-bottom text-sm",s),...t})})}function Be({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:x("[&_tr]:border-b",s),...t})}function qe({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:x("[&_tr:last-child]:border-0",s),...t})}function te({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:x("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:x("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 $({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:x("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}const _e=["pending","provisioning","ready","failed"],Ie=["master","worker","bastion"],Ys=W({hostname:V().trim().max(120,"Max 120 chars").optional(),ip_address:V().trim().min(1,"IP address is required"),role:ye(Ie),ssh_key_id:ss("Pick a valid SSH key"),ssh_user:V().trim().min(1,"SSH user is required"),status:ye(_e).default("pending")}),_r=Ys.partial();function Ir({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Fe,{variant:t,className:"capitalize",children:s})}function Qe(s,t=16){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}const Er=()=>{const[s,t]=c.useState([]),[a,n]=c.useState([]),[m,u]=c.useState(!1),[f,j]=c.useState(null),[N,g]=c.useState(""),[k,E]=c.useState(""),[_,S]=c.useState(""),[L,T]=c.useState(!1),[F,l]=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 o(){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(()=>{o();const i=r=>{r.key==="active_org_id"&&o()};return window.addEventListener("storage",i),()=>window.removeEventListener("storage",i)},[]),c.useEffect(()=>{o()},[k,_]);const p=c.useMemo(()=>{const i=new Map;return a.forEach(r=>i.set(r.id,r)),i},[a]),A=c.useMemo(()=>{const i=N.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,N]);async function H(i){confirm("Delete this server? This cannot be undone.")&&(await z.delete(`/api/v1/servers/${encodeURIComponent(i)}`),await o())}const R=q({resolver:G(Ys),defaultValues:{hostname:"",ip_address:"",role:"worker",ssh_key_id:"",ssh_user:"ubuntu",status:"pending"}}),X=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),T(!1),R.reset(),await o()},U=q({resolver:G(_r),defaultValues:{}});function we(i){l(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),l(null),await o()};return m?e.jsx("div",{className:"p-6",children:"Loading servers…"}):f?e.jsx("div",{className:"p-6 text-red-500",children:f}):e.jsxs(Je,{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(D,{value:N,onChange:i=>g(i.target.value),placeholder:"Search hostname, IP, role, user…",className:"w-64 pl-8"})]}),e.jsxs(Q,{value:_,onValueChange:i=>S(i),children:[e.jsx(ee,{className:"w-36",children:e.jsx(Z,{placeholder:"Role (all)"})}),e.jsx(se,{children:Ie.map(i=>e.jsx(B,{value:i,children:i},i))})]}),e.jsxs(Q,{value:k,onValueChange:i=>E(i),children:[e.jsx(ee,{className:"w-40",children:e.jsx(Z,{placeholder:"Status (all)"})}),e.jsx(se,{children:_e.map(i=>e.jsx(B,{value:i,children:i},i))})]}),e.jsxs(h,{variant:"outline",onClick:o,children:[e.jsx(Vs,{className:"mr-2 h-4 w-4"}),"Refresh"]}),e.jsxs(oe,{open:L,onOpenChange:T,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>T(!0),children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Create Server"]})}),e.jsxs(le,{className:"sm:max-w-lg",children:[e.jsx(de,{children:e.jsx(me,{children:"Create server"})}),e.jsx(K,{...R,children:e.jsxs("form",{onSubmit:R.handleSubmit(X),className:"space-y-4",children:[e.jsx(v,{control:R.control,name:"hostname",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Hostname"}),e.jsx(C,{children:e.jsx(D,{placeholder:"worker-01",...i})}),e.jsx(y,{})]})}),e.jsx(v,{control:R.control,name:"ip_address",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"IP address"}),e.jsx(C,{children:e.jsx(D,{placeholder:"10.0.1.23",...i})}),e.jsx(y,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(v,{control:R.control,name:"role",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Role"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:"Select role"})})}),e.jsx(se,{children:Ie.map(r=>e.jsx(B,{value:r,children:r},r))})]}),e.jsx(y,{})]})}),e.jsx(v,{control:R.control,name:"ssh_user",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"SSH user"}),e.jsx(C,{children:e.jsx(D,{placeholder:"ubuntu",...i})}),e.jsx(y,{})]})})]}),e.jsx(v,{control:R.control,name:"ssh_key_id",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"SSH key"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:a.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(se,{children:a.map(r=>e.jsxs(B,{value:r.id,children:[r.name?r.name:"Unnamed key"," —"," ",Qe(r.fingerprint,8)]},r.id))})]}),e.jsx(y,{})]})}),e.jsx(v,{control:R.control,name:"status",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Initial status"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:"pending"})})}),e.jsx(se,{children:_e.map(r=>e.jsx(B,{value:r,children:r},r))})]}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>T(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:R.formState.isSubmitting,children:R.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(Ue,{children:[e.jsx(Be,{children:e.jsxs(te,{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(qe,{children:[A.map(i=>{const r=p.get(i.ssh_key_id);return e.jsxs(te,{children:[e.jsx($,{className:"font-medium",children:i.hostname||"—"}),e.jsx($,{children:e.jsx("code",{className:"font-mono text-sm",children:i.ip_address})}),e.jsx($,{className:"capitalize",children:i.role}),e.jsx($,{children:e.jsx("code",{className:"font-mono text-sm",children:i.ssh_user})}),e.jsx($,{children:r?e.jsxs(os,{children:[e.jsx(ls,{asChild:!0,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Fe,{variant:"secondary",children:r.name||"SSH key"}),e.jsx("code",{className:"font-mono text-xs",children:Qe(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($,{children:e.jsx(Ir,{status:i.status})}),e.jsx($,{children:new Date(i.created_at).toLocaleString()}),e.jsx($,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>we(i),children:[e.jsx(as,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs($e,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Se,{className:"mr-2 h-4 w-4"})," Delete"]})}),e.jsx(Pe,{align:"end",children:e.jsx(ie,{onClick:()=>H(i.id),children:"Confirm delete"})})]})]})})]},i.id)}),A.length===0&&e.jsx(te,{children:e.jsx($,{colSpan:8,className:"text-muted-foreground py-10 text-center",children:"No servers match your filters."})})]})]})})})]}),e.jsx(oe,{open:!!F,onOpenChange:i=>!i&&l(null),children:e.jsxs(le,{className:"sm:max-w-lg",children:[e.jsx(de,{children:e.jsx(me,{children:"Edit server"})}),e.jsx(K,{...U,children:e.jsxs("form",{onSubmit:U.handleSubmit(xe),className:"space-y-4",children:[e.jsx(v,{control:U.control,name:"hostname",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Hostname"}),e.jsx(C,{children:e.jsx(D,{placeholder:"worker-01",...i})}),e.jsx(y,{})]})}),e.jsx(v,{control:U.control,name:"ip_address",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"IP address"}),e.jsx(C,{children:e.jsx(D,{placeholder:"10.0.1.23",...i})}),e.jsx(y,{})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx(v,{control:U.control,name:"role",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Role"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:"Select role"})})}),e.jsx(se,{children:Ie.map(r=>e.jsx(B,{value:r,children:r},r))})]}),e.jsx(y,{})]})}),e.jsx(v,{control:U.control,name:"ssh_user",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"SSH user"}),e.jsx(C,{children:e.jsx(D,{placeholder:"ubuntu",...i})}),e.jsx(y,{})]})})]}),e.jsx(v,{control:U.control,name:"ssh_key_id",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"SSH key"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:a.length?"Select SSH key":"No SSH keys found"})})}),e.jsx(se,{children:a.map(r=>e.jsxs(B,{value:r.id,children:[r.name?r.name:"SSH key"," — ",Qe(r.fingerprint,8)]},r.id))})]}),e.jsx(y,{})]})}),e.jsx(v,{control:U.control,name:"status",render:({field:i})=>e.jsxs(b,{children:[e.jsx(w,{children:"Status"}),e.jsxs(Q,{onValueChange:i.onChange,value:i.value,children:[e.jsx(C,{children:e.jsx(ee,{children:e.jsx(Z,{placeholder:"pending"})})}),e.jsx(se,{children:_e.map(r=>e.jsx(B,{value:r,children:r},r))})]}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>l(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:U.formState.isSubmitting,children:U.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})})]})};function Ss(){return e.jsxs("div",{className:"p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"403 — Forbidden"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"You don’t have access to this area."})]})}const Cs=()=>{const s=Te();return e.jsxs("div",{className:"bg-background text-foreground flex min-h-screen flex-col items-center justify-center",children:[e.jsx("h1",{className:"mb-4 text-6xl font-bold",children:"404"}),e.jsx("p",{className:"mb-8 text-2xl",children:"Oops! Page not found"}),e.jsx(h,{onClick:()=>s("/dashboard"),children:"Go back to Dashboard"})]})},zr=W({name:V().min(1,"Name is required").max(100,"Max 100 characters"),comment:V().trim().max(100,"Max 100 characters").default(""),bits:ye(["2048","3072","4096"])});function Or(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 Ar(s,t=24){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}function Dr(s){return s?.split(/\s+/)?.[0]??"ssh-key"}async function Lr(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 Tr=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(null),[m,u]=c.useState(!0),[f,j]=c.useState(""),[N,g]=c.useState(!1),k=c.useMemo(()=>!!localStorage.getItem("active_org_id"),[]);async function E(){u(!0),n(null);try{if(!k){t([]),n("Select an organization first.");return}const l=await z.get("/api/v1/ssh");t(l??[])}catch(l){console.error(l),n("Failed to fetch SSH keys")}finally{u(!1)}}c.useEffect(()=>{E();const l=d=>{d.key==="active_org_id"&&E()};return window.addEventListener("storage",l),()=>window.removeEventListener("storage",l)},[]);const _=s.filter(l=>`${l.name} ${l.public_keys} ${l.fingerprint}`.toLowerCase().includes(f.toLowerCase()));async function S(l,d="both"){const o=localStorage.getItem("access_token"),p=localStorage.getItem("active_org_id"),A=`${Ve}/api/v1/ssh/${encodeURIComponent(l)}/download?part=${encodeURIComponent(d)}`;try{const H=await fetch(A,{method:"GET",headers:{...o?{Authorization:`Bearer ${o}`}:{},...p?{"X-Org-ID":p}:{}}});if(!H.ok){const i=await H.text().catch(()=>"");throw new Error(i||`HTTP ${H.status}`)}const R=await H.blob(),X=d==="both"?`ssh_key_${l}.zip`:d==="public"?`id_rsa_${l}.pub`:`id_rsa_${l}.pem`,U=Or(H.headers.get("content-disposition")??void 0,X),we=URL.createObjectURL(R),xe=document.createElement("a");xe.href=we,xe.download=U,document.body.appendChild(xe),xe.click(),xe.remove(),URL.revokeObjectURL(we)}catch(H){console.error(H),alert(H instanceof Error?H.message:"Download failed")}}async function L(l){try{await z.delete(`/api/v1/ssh/${encodeURIComponent(l)}`),await E()}catch(d){console.error(d),alert("Failed to delete key")}}const T=q({resolver:G(zr),defaultValues:{name:"",comment:"deploy@autoglue",bits:"4096"}});async function F(l){try{await z.post("/api/v1/ssh",{bits:Number(l.bits),comment:l.comment?.trim()??"",name:l.name.trim(),download:"none"}),g(!1),T.reset(),await E()}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(Je,{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(D,{value:f,onChange:l=>j(l.target.value),placeholder:"Search by name, fingerprint or key"})}),e.jsxs(oe,{open:N,onOpenChange:g,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>g(!0),children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Create New Keypair"]})}),e.jsxs(le,{className:"sm:max-w-lg",children:[e.jsx(de,{children:e.jsx(me,{children:"Create SSH Keypair"})}),e.jsx(K,{...T,children:e.jsxs("form",{onSubmit:T.handleSubmit(F),className:"space-y-4",children:[e.jsx(v,{control:T.control,name:"name",render:({field:l})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{placeholder:"e.g., CI deploy key",...l})}),e.jsx(y,{})]})}),e.jsx(v,{control:T.control,name:"comment",render:({field:l})=>e.jsxs(b,{children:[e.jsx(w,{children:"Comment"}),e.jsx(C,{children:e.jsx(D,{placeholder:"e.g., deploy@autoglue",...l})}),e.jsx(y,{})]})}),e.jsx(v,{control:T.control,name:"bits",render:({field:l})=>e.jsxs(b,{children:[e.jsx(w,{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:l.value,onChange:l.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(y,{})]})}),e.jsxs(ce,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:T.formState.isSubmitting,children:T.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(Ue,{children:[e.jsx(Be,{children:e.jsxs(te,{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(qe,{children:_.map(l=>{const d=Dr(l.public_keys),o=Ar(l.public_keys,18);return e.jsxs(te,{children:[e.jsx($,{className:"align-top",children:l.name}),e.jsx($,{className:"align-top",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Fe,{variant:"secondary",className:"whitespace-nowrap",children:d}),e.jsxs(os,{children:[e.jsx(ls,{asChild:!0,children:e.jsx("code",{className:"font-mono text-sm break-all md:max-w-[48ch] md:truncate md:break-normal",children:o})}),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:l.public_keys})})})]})]})}),e.jsx($,{className:"align-top",children:e.jsx("code",{className:"font-mono text-sm",children:l.fingerprint})}),e.jsx($,{className:"align-top",children:new Date(l.created_at).toLocaleString(void 0,{year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),e.jsx($,{className:"align-top",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Lr(l.public_keys),title:"Copy public key",children:[e.jsx(xa,{className:"mr-2 h-4 w-4"}),"Copy"]}),e.jsxs($e,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(h,{variant:"outline",size:"sm",children:[e.jsx(ha,{className:"mr-2 h-4 w-4"}),"Download"]})}),e.jsxs(Pe,{align:"end",children:[e.jsx(ie,{onClick:()=>S(l.id,"both"),children:"Public + Private (.zip)"}),e.jsx(ie,{onClick:()=>S(l.id,"public"),children:"Public only (.pub)"}),e.jsx(ie,{onClick:()=>S(l.id,"private"),children:"Private only (.pem)"})]})]}),e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>L(l.id),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),"Delete"]})]})})]},l.id)})})]})})})]})})};function $r(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 Mr=W({email:Ne("Enter a valid email"),role:ye(["member","admin"])}),Pr=()=>{const[s,t]=c.useState(!0),[a,n]=c.useState([]),[m,u]=c.useState(null),[f,j]=c.useState(!1),[N,g]=c.useState(!1),[k,E]=c.useState(null),_=c.useMemo(()=>je(),[]),S=q({resolver:G(Mr),defaultValues:{email:"",role:"member"},mode:"onChange"});async function L(){try{const d=await z.get("/api/v1/auth/me");u(d)}catch{}}async function T(d){if(!d){n([]),t(!1);return}t(!0);try{const o=await z.get("/api/v1/orgs/members");n((o??[]).map($r))}catch(o){const p=o instanceof J?o.message:"Failed to load members";O.error(p)}finally{t(!1)}}c.useEffect(()=>{L(),T(_)},[_]),c.useEffect(()=>{const d=()=>void T(je()),o=p=>{p.key==="active_org_id"&&d()};return window.addEventListener(be,d),window.addEventListener("storage",o),()=>{window.removeEventListener(be,d),window.removeEventListener("storage",o)}},[]);async function F(d){const o=je();if(!o){O.error("Select an organization first");return}try{g(!0),await z.post("/api/v1/orgs/invite",d),O.success(`Invited ${d.email}`),j(!1),S.reset({email:"",role:"member"}),T(o)}catch(p){const A=p instanceof J?p.message:"Failed to invite member";O.error(A)}finally{g(!1)}}async function l(d){const o=je();if(!o){O.error("Select an organization first");return}try{E(d),await z.delete(`/api/v1/orgs/members/${d}`,{headers:{"X-Org-ID":o}}),n(p=>p.filter(A=>A.userId!==d)),O.success("Member removed")}catch(p){const A=p instanceof J?p.message:"Failed to remove member";O.error(A)}finally{E(null)}}return s?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Members"}),e.jsxs(h,{disabled:!0,children:[e.jsx(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,o)=>e.jsxs(ae,{children:[e.jsx(re,{children:e.jsx(fe,{className:"h-5 w-40"})}),e.jsxs(ne,{className:"space-y-2",children:[e.jsx(fe,{className:"h-4 w-56"}),e.jsx(fe,{className:"h-4 w-40"})]}),e.jsx(De,{children:e.jsx(fe,{className:"h-9 w-24"})})]},o))})]}):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(oe,{open:f,onOpenChange:j,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{children:[e.jsx(bs,{className:"mr-2 h-4 w-4"}),"Invite"]})}),e.jsxs(le,{className:"sm:max-w-[520px]",children:[e.jsxs(de,{children:[e.jsx(me,{children:"Invite member"}),e.jsx(He,{children:"Send an invite to join this organization."})]}),e.jsx(K,{...S,children:e.jsxs("form",{onSubmit:S.handleSubmit(F),className:"grid gap-4 py-2",children:[e.jsx(v,{control:S.control,name:"email",render:({field:d})=>e.jsxs(b,{children:[e.jsx(w,{children:"Email"}),e.jsx(C,{children:e.jsx(D,{type:"email",placeholder:"jane@example.com",...d})}),e.jsx(y,{})]})}),e.jsx(v,{control:S.control,name:"role",render:({field:d})=>e.jsxs(b,{children:[e.jsx(w,{children:"Role"}),e.jsxs(Q,{onValueChange:d.onChange,defaultValue:d.value,children:[e.jsx(C,{children:e.jsx(ee,{className:"w-[200px]",children:e.jsx(Z,{placeholder:"Select role"})})}),e.jsxs(se,{children:[e.jsx(B,{value:"member",children:"Member"}),e.jsx(B,{value:"admin",children:"Admin"})]})]}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"mt-2 flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!S.formState.isValid||N,children:N?"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 o=m?.id&&d.userId===m.id;return e.jsxs(ae,{className:"flex flex-col",children:[e.jsx(re,{children:e.jsx(he,{className:"text-base",children:d.name||d.email||d.userId})}),e.jsxs(ne,{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(De,{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(h,{variant:"destructive",disabled:o||k===d.userId,className:"ml-auto",children:[e.jsx(Se,{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(h,{variant:"destructive",onClick:()=>l(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."})]})},Fr=W({name:V().min(2).max(100),slug:V().min(2).max(50).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Use lowercase letters, numbers, and hyphens.")}),Rr=()=>{const[s,t]=c.useState([]),[a,n]=c.useState(!0),[m,u]=c.useState(!1),[f,j]=c.useState(null),[N,g]=c.useState(null),k=c.useRef(!1),E=q({resolver:G(Fr),mode:"onChange",defaultValues:{name:"",slug:""}}),_=E.watch("name");c.useEffect(()=>{k.current||E.setValue("slug",ws(_||""),{shouldValidate:!0})},[_,E]);const S=async()=>{n(!0);try{const l=await z.get("/api/v1/orgs");t(l),u(l.length===0)}catch(l){const d=l instanceof J?l.message:"Failed to load organizations";O.error(d)}finally{n(!1)}};c.useEffect(()=>{j(je()),S();const l=p=>{p.key==="active_org_id"&&j(p.newValue)};window.addEventListener("storage",l);const d=p=>{const A=p.detail??null;j(A)};window.addEventListener(be,d);const o=()=>void S();return window.addEventListener(Ae,o),()=>{window.removeEventListener("storage",l),window.removeEventListener(be,d),window.removeEventListener(Ae,o)}},[]);async function L(l){try{const d=await z.post("/api/v1/orgs",l);t(o=>[d,...o]),Oe(d.id),j(d.id),ys(),O.success(`Created ${d.name}`),u(!1),E.reset({name:"",slug:""}),k.current=!1}catch(d){const o=d instanceof J?d.message:"Failed to create organization";O.error(o)}}function T(l){Oe(l.id),j(l.id),O.success(`Switched to ${l.name}`)}async function F(l){try{g(l.id),await z.delete(`/api/v1/orgs/${l.id}`),t(d=>{const o=d.filter(p=>p.id!==l.id);if(f===l.id){const p=o[0]?.id??null;Oe(p),j(p)}return o}),ys(),O.success(`Deleted ${l.name}`)}catch(d){const o=d instanceof J?d.message:"Failed to delete organization";O.error(o)}finally{g(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((l,d)=>e.jsxs(ae,{children:[e.jsx(re,{children:e.jsx(fe,{className:"h-5 w-40"})}),e.jsxs(ne,{children:[e.jsx(fe,{className:"mb-2 h-4 w-24"}),e.jsx(fe,{className:"h-4 w-48"})]}),e.jsx(De,{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(h,{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(l=>e.jsxs(ae,{className:"flex flex-col",children:[e.jsx(re,{children:e.jsx(he,{className:"text-base",children:l.name})}),e.jsxs(ne,{className:"text-muted-foreground text-sm",children:[e.jsxs("div",{children:["Slug: ",l.slug]}),e.jsxs("div",{className:"mt-1",children:["ID: ",l.id]})]}),e.jsxs(De,{className:"mt-auto w-full flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{onClick:()=>T(l),children:l.id===f?"Selected":"Select"}),e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(h,{variant:"destructive",className:"ml-auto",disabled:N===l.id,children:[e.jsx(Se,{className:"mr-2 h-5 w-5"}),N===l.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:l.name}),". This action cannot be undone."]})]}),e.jsxs(hs,{className:"sm:justify-between",children:[e.jsx(ps,{disabled:N===l.id,children:"Cancel"}),e.jsx(gs,{asChild:!0,disabled:N===l.id,children:e.jsx(h,{variant:"destructive",onClick:()=>F(l),children:"Confirm delete"})})]})]})]})]})]},l.id))}),e.jsx(oe,{open:m,onOpenChange:u,children:e.jsxs(le,{className:"sm:max-w-[480px]",children:[e.jsxs(de,{children:[e.jsx(me,{children:"Create organization"}),e.jsx(He,{children:"Set a name and a URL-friendly slug."})]}),e.jsx(K,{...E,children:e.jsxs("form",{onSubmit:E.handleSubmit(L),className:"space-y-4",children:[e.jsx(v,{control:E.control,name:"name",render:({field:l})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{placeholder:"Acme Inc",autoFocus:!0,...l})}),e.jsx(Ns,{children:"This is your organization’s display name."}),e.jsx(y,{})]})}),e.jsx(v,{control:E.control,name:"slug",render:({field:l})=>e.jsxs(b,{children:[e.jsx(w,{children:"Slug"}),e.jsx(C,{children:e.jsx(D,{placeholder:"acme-inc",...l,onChange:d=>{k.current=!0,l.onChange(d)},onBlur:d=>{const o=ws(d.target.value);E.setValue("slug",o,{shouldValidate:!0}),l.onBlur()}})}),e.jsx(Ns,{children:"Lowercase, numbers and hyphens only."}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>{E.reset(),u(!1),k.current=!1},children:"Cancel"}),e.jsx(h,{type:"submit",disabled:!E.formState.isValid||E.formState.isSubmitting,children:E.formState.isSubmitting?"Creating...":"Create"})]})]})})]})})]})};function ks({className:s,...t}){return e.jsx(qt,{"data-slot":"checkbox",className:x("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 Vr=W({name:V().trim().min(1,"Name is required").max(120,"Max 120 chars"),server_ids:zs(ss()).optional().default([])}),Hr=W({name:V().trim().min(1,"Name is required").max(120,"Max 120 chars")}),Ur=W({server_ids:zs(ss()).min(1,"Pick at least one server")});function _s({status:s}){const t=s==="ready"?"default":s==="provisioning"?"secondary":s==="failed"?"destructive":"outline";return e.jsx(Fe,{variant:t,className:"capitalize",children:s||"unknown"})}function Re(s,t=12){return!s||s.length<=t*2+3?s:`${s.slice(0,t)}…${s.slice(-t)}`}function Is(s){const t=s.ip||s.ip_address,a=s.hostname||t||s.id,n=s.role?` · ${s.role}`:"";return`${a}${n}`}const Br=()=>{const[s,t]=c.useState(!0),[a,n]=c.useState([]),[m,u]=c.useState([]),[f,j]=c.useState(null),[N,g]=c.useState(""),[k,E]=c.useState(!1),[_,S]=c.useState(null),[L,T]=c.useState(null);async function F(){t(!0),j(null);try{const[r,I]=await Promise.all([z.get("/api/v1/node-pools?include=servers"),z.get("/api/v1/servers")]);if(n(r||[]),u(I||[]),L){const Y=(r||[]).find(ge=>ge.id===L.id)||null;T(Y)}if(_){const Y=(r||[]).find(ge=>ge.id===_.id)||null;S(Y)}}catch(r){console.error(r);const I=r instanceof J?r.message:"Failed to load node pools or servers";j(I)}finally{t(!1)}}c.useEffect(()=>{F()},[]);const l=c.useMemo(()=>{const r=N.trim().toLowerCase();return r?a.filter(I=>I.name.toLowerCase().includes(r)||(I.servers||[]).some(Y=>(Y.hostname||"").toLowerCase().includes(r)||(Y.ip||Y.ip_address||"").toLowerCase().includes(r)||(Y.role||"").toLowerCase().includes(r))):a},[a,N]);async function d(r){confirm("Delete this node pool? This cannot be undone.")&&(await z.delete(`/api/v1/node-pools/${r}`),await F())}const o=q({resolver:G(Vr),defaultValues:{name:"",server_ids:[]}}),p=async r=>{const I={name:r.name.trim()};r.server_ids&&r.server_ids.length>0&&(I.server_ids=r.server_ids),await z.post("/api/v1/node-pools",I),E(!1),o.reset({name:"",server_ids:[]}),await F()},A=q({resolver:G(Hr),defaultValues:{name:""}});function H(r){S(r),A.reset({name:r.name})}const R=async r=>{_&&(await z.patch(`/api/v1/node-pools/${_.id}`,{name:r.name.trim()}),S(null),await F())},X=q({resolver:G(Ur),defaultValues:{server_ids:[]}});function U(r){T(r),X.reset({server_ids:[]})}const we=async r=>{L&&(await z.post(`/api/v1/node-pools/${L.id}/servers`,{server_ids:r.server_ids}),X.reset({server_ids:[]}),await F())};async function xe(r){L&&confirm("Detach this server from the pool?")&&(await z.delete(`/api/v1/node-pools/${L.id}/servers/${r}`),await F())}const i=c.useMemo(()=>{if(!L)return[];const r=new Set((L.servers||[]).map(I=>I.id));return m.filter(I=>!r.has(I.id))},[L,m]);return s?e.jsx("div",{className:"p-6",children:"Loading node pools…"}):f?e.jsx("div",{className:"p-6 text-red-500",children:f}):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 left-2 top-2.5 h-4 w-4 opacity-60"}),e.jsx(D,{value:N,onChange:r=>g(r.target.value),placeholder:"Search pools or servers…",className:"pl-8 w-72"})]}),e.jsxs(h,{variant:"outline",onClick:F,children:[e.jsx(Vs,{className:"h-4 w-4 mr-2"})," Refresh"]}),e.jsxs(oe,{open:k,onOpenChange:E,children:[e.jsx(We,{asChild:!0,children:e.jsxs(h,{onClick:()=>E(!0),children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"})," Create Pool"]})}),e.jsxs(le,{className:"sm:max-w-lg",children:[e.jsx(de,{children:e.jsx(me,{children:"Create node pool"})}),e.jsx(K,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(p),className:"space-y-4",children:[e.jsx(v,{control:o.control,name:"name",render:({field:r})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{placeholder:"pool-workers-a",...r})}),e.jsx(y,{})]})}),e.jsx(v,{control:o.control,name:"server_ids",render:({field:r})=>e.jsxs(b,{children:[e.jsx(w,{children:"Initial servers (optional)"}),e.jsxs("div",{className:"max-h-56 overflow-auto rounded-xl border p-2 space-y-2",children:[m.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground p-2",children:"No servers available"}),m.map(I=>{const Y=r.value?.includes(I.id)||!1;return e.jsxs("label",{className:"flex items-start gap-2 p-1 rounded hover:bg-accent cursor-pointer",children:[e.jsx(ks,{checked:Y,onCheckedChange:ge=>{const pe=new Set(r.value||[]);ge===!0?pe.add(I.id):pe.delete(I.id),r.onChange(Array.from(pe))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"font-medium text-sm",children:Is(I)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:Re(I.id,8)})]})]},I.id)})]}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>E(!1),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:o.formState.isSubmitting,children:o.formState.isSubmitting?"Creating…":"Create"})]})]})})]})]})]})]}),e.jsx("div",{className:"rounded-2xl border bg-background shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ue,{children:[e.jsx(Be,{children:e.jsxs(te,{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(qe,{children:[l.map(r=>e.jsxs(te,{children:[e.jsx($,{className:"font-medium",children:r.name}),e.jsxs($,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(r.servers||[]).slice(0,6).map(I=>e.jsxs(Fe,{variant:"secondary",className:"gap-1",children:[e.jsx(Fs,{className:"h-3 w-3"})," ",I.hostname||I.ip||I.ip_address||Re(I.id,6),I.status&&e.jsx("span",{className:"ml-1",children:e.jsx(_s,{status:I.status})})]},I.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(h,{variant:"outline",size:"sm",onClick:()=>U(r),children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," Manage servers"]})]}),e.jsxs($,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Annotations"}),e.jsxs(h,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," Manage Annotations"]})]}),e.jsxs($,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Labels"}),e.jsxs(h,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," Manage Labels"]})]}),e.jsxs($,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:"Taints"}),e.jsxs(h,{variant:"outline",size:"sm",children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," Manage Taints"]})]}),e.jsx($,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>H(r),children:[e.jsx(as,{className:"h-4 w-4 mr-2"})," Edit"]}),e.jsxs($e,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(h,{variant:"destructive",size:"sm",children:[e.jsx(Se,{className:"h-4 w-4 mr-2"})," Delete"]})}),e.jsx(Pe,{align:"end",children:e.jsx(ie,{onClick:()=>d(r.id),children:"Confirm delete"})})]})]})})]},r.id)),l.length===0&&e.jsx(te,{children:e.jsx($,{colSpan:3,className:"text-center text-muted-foreground py-10",children:"No node pools match your search."})})]})]})})}),e.jsx(oe,{open:!!_,onOpenChange:r=>!r&&S(null),children:e.jsxs(le,{className:"sm:max-w-md",children:[e.jsx(de,{children:e.jsx(me,{children:"Edit node pool"})}),e.jsx(K,{...A,children:e.jsxs("form",{onSubmit:A.handleSubmit(R),className:"space-y-4",children:[e.jsx(v,{control:A.control,name:"name",render:({field:r})=>e.jsxs(b,{children:[e.jsx(w,{children:"Name"}),e.jsx(C,{children:e.jsx(D,{placeholder:"pool-workers-a",...r})}),e.jsx(y,{})]})}),e.jsxs(ce,{className:"gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>S(null),children:"Cancel"}),e.jsx(h,{type:"submit",disabled:A.formState.isSubmitting,children:A.formState.isSubmitting?"Saving…":"Save changes"})]})]})})]})}),e.jsx(oe,{open:!!L,onOpenChange:r=>!r&&T(null),children:e.jsxs(le,{className:"sm:max-w-2xl",children:[e.jsx(de,{children:e.jsxs(me,{children:["Manage servers for ",e.jsx("span",{className:"font-mono",children:L?.name})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Attached servers"}),e.jsx("div",{className:"rounded-xl border overflow-hidden",children:e.jsxs(Ue,{children:[e.jsx(Be,{children:e.jsxs(te,{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(qe,{children:[(L?.servers||[]).map(r=>e.jsxs(te,{children:[e.jsx($,{className:"font-medium",children:r.hostname||Re(r.id,8)}),e.jsx($,{children:e.jsx("code",{className:"font-mono text-sm",children:r.ip||r.ip_address||"—"})}),e.jsx($,{className:"capitalize",children:r.role||"—"}),e.jsx($,{children:e.jsx(_s,{status:r.status})}),e.jsx($,{children:e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>xe(r.id),children:[e.jsx(ja,{className:"h-4 w-4 mr-2"})," Detach"]})})})]},r.id)),(L?.servers||[]).length===0&&e.jsx(te,{children:e.jsx($,{colSpan:5,className:"text-center text-muted-foreground py-8",children:"No servers attached yet."})})]})]})})]}),e.jsx("div",{className:"pt-4",children:e.jsx(K,{...X,children:e.jsxs("form",{onSubmit:X.handleSubmit(we),className:"space-y-3",children:[e.jsx(v,{control:X.control,name:"server_ids",render:({field:r})=>e.jsxs(b,{children:[e.jsx(w,{children:"Attach more servers"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2 max-h-64 overflow-auto rounded-xl border p-2",children:[i.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground p-2",children:"No more servers available to attach"}),i.map(I=>{const Y=r.value?.includes(I.id)||!1;return e.jsxs("label",{className:"flex items-start gap-2 p-1 rounded hover:bg-accent cursor-pointer",children:[e.jsx(ks,{checked:Y,onCheckedChange:ge=>{const pe=new Set(r.value||[]);ge===!0?pe.add(I.id):pe.delete(I.id),r.onChange(Array.from(pe))}}),e.jsxs("div",{className:"leading-tight",children:[e.jsx("div",{className:"font-medium text-sm",children:Is(I)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:Re(I.id,8)})]})]},I.id)})]}),e.jsx(y,{})]})}),e.jsx(ce,{className:"gap-2",children:e.jsxs(h,{type:"submit",disabled:X.formState.isSubmitting,children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," ",X.formState.isSubmitting?"Attaching…":"Attach selected"]})})]})})})]})})]})};function qr(){return e.jsxs(fa,{children:[e.jsx(M,{path:"/",element:e.jsx(ns,{to:"/auth/login",replace:!0})}),e.jsxs(M,{path:"/auth",children:[e.jsx(M,{path:"login",element:e.jsx(vr,{})}),e.jsx(M,{path:"register",element:e.jsx(yr,{})}),e.jsx(M,{path:"forgot",element:e.jsx(gr,{})}),e.jsx(M,{path:"reset",element:e.jsx(Sr,{})}),e.jsx(M,{path:"verify",element:e.jsx(Cr,{})})]}),e.jsx(M,{element:e.jsx(rr,{}),children:e.jsxs(M,{element:e.jsx(ar,{}),children:[e.jsx(M,{element:e.jsx(nr,{}),children:e.jsx(M,{path:"/admin",children:e.jsx(M,{path:"users",element:e.jsx(jr,{})})})}),e.jsxs(M,{path:"/core",children:[e.jsx(M,{path:"nodepools",element:e.jsx(Br,{})}),e.jsx(M,{path:"servers",element:e.jsx(Er,{})})]}),e.jsx(M,{path:"/security",children:e.jsx(M,{path:"ssh",element:e.jsx(Tr,{})})}),e.jsxs(M,{path:"/settings",children:[e.jsx(M,{path:"orgs",element:e.jsx(Rr,{})}),e.jsx(M,{path:"members",element:e.jsx(Pr,{})}),e.jsx(M,{path:"me",element:e.jsx(br,{})})]}),e.jsx(M,{path:"/403",element:e.jsx(Ss,{})}),e.jsx(M,{path:"*",element:e.jsx(Cs,{})})]})}),e.jsx(M,{path:"/403",element:e.jsx(Ss,{})}),e.jsx(M,{path:"*",element:e.jsx(Cs,{})})]})}const Gr=({...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 Kr({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(Kr,{defaultTheme:"system",storageKey:"dragon-theme",children:[e.jsx(qr,{}),e.jsx(Gr,{richColors:!0,position:"top-right"})]})})}));
|