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