1import{r as x,j as e}from"./react-vendor-R5HqukZ7.js";import{al as D,b6 as T,ao as u,bA as z,B as r,H as t,a2 as H,ap as g,aq as b,ar as N,as as f,at as S,au as B,C as L,g as O,h as W,j as U,k as F,bH as M,bI as G,bJ as v,bK as i,bL as R,bM as n,bn as _,cb as E,bi as Y,aU as q,a8 as J}from"./main-Ccz3IRrk.js";import{c as Q,b as c,a as h}from"./convex-BevPdSW0.js";import"./motion-Pabu1yrW.js";function se(){const{workspaceId:a}=D({from:"/dashboard/$workspaceId/settings/api-keys"}),{state:Z}=T(),[l,m]=x.useState(null),[j,p]=x.useState(""),[C,y]=x.useState(!1),{data:o,isLoading:K}=Q(c.apiKeys.list,a?{workspaceId:a}:"skip"),k=h(c.apiKeys.generate),w=h(c.apiKeys.revoke),I=h(c.apiKeys.deleteKey),A=async()=>{if(a)try{const s=await k({workspaceId:a,name:j.trim()||"Untitled Key"});m(s.apiKey),p(""),y(!1)}catch(s){console.error("Failed to generate API key",s)}},P=s=>{navigator.clipboard.writeText(s)};return e.jsx("div",{className:"flex-1 p-8",children:e.jsxs("div",{className:"max-w-5xl space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"API Keys"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Manage API keys for programmatic access to Berrydesk"})]}),e.jsxs(u,{open:C,onOpenChange:y,children:[e.jsx(z,{asChild:!0,children:e.jsxs(r,{children:[e.jsx(t,{icon:H,size:16,strokeWidth:2,className:"mr-2"}),"Create API Key"]})}),e.jsxs(g,{children:[e.jsxs(b,{children:[e.jsx(N,{children:"Create API Key"}),e.jsx(f,{children:"Generate a new API key for programmatic access"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(S,{htmlFor:"key-name",children:"Key Name"}),e.jsx(B,{id:"key-name",placeholder:"Production API Key",value:j,onChange:s=>p(s.target.value)})]}),e.jsx(r,{onClick:A,className:"w-full",disabled:!a,children:"Generate Key"})]})]})]})]}),e.jsxs(L,{children:[e.jsxs(O,{children:[e.jsx(W,{children:"Your API Keys"}),e.jsx(U,{children:"Keep your API keys secure. They provide full access to your workspace."})]}),e.jsx(F,{children:K?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):o&&o.length>0?e.jsxs(M,{children:[e.jsx(G,{children:e.jsxs(v,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Key"}),e.jsx(i,{children:"Last Used"}),e.jsx(i,{children:"Status"}),e.jsx(i,{className:"w-[100px]"})]})}),e.jsx(R,{children:o.map(s=>e.jsxs(v,{children:[e.jsx(n,{className:"font-medium",children:s.name}),e.jsxs(n,{className:"font-mono text-sm",children:[s.keyPrefix,"..."]}),e.jsx(n,{className:"text-sm text-muted-foreground",children:s.lastUsedAt?new Date(s.lastUsedAt).toLocaleDateString():"Never"}),e.jsx(n,{children:e.jsx(_,{variant:s.isActive?"default":"secondary",children:s.isActive?"Active":"Revoked"})}),e.jsx(n,{children:e.jsxs("div",{className:"flex gap-1",children:[s.isActive&&e.jsx(r,{variant:"ghost",size:"icon",onClick:async()=>{try{await w({keyId:s._id})}catch(d){console.error("Failed to revoke API key",d)}},children:e.jsx(t,{icon:E,size:16,strokeWidth:2})}),e.jsx(r,{variant:"ghost",size:"icon",onClick:async()=>{try{await I({keyId:s._id})}catch(d){console.error("Failed to delete API key",d)}},children:e.jsx(t,{icon:Y,size:16,strokeWidth:2,className:"text-red-600"})})]})})]},s._id))})]}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(t,{icon:q,size:16,strokeWidth:2,className:"mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No API keys yet"})]})})]}),e.jsx(u,{open:!!l,onOpenChange:s=>{s||m(null)},children:e.jsxs(g,{children:[e.jsxs(b,{children:[e.jsx(N,{children:"API Key Created"}),e.jsx(f,{children:"Copy this key now. You won't be able to see it again!"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"p-4 bg-muted rounded-lg",children:e.jsx("p",{className:"text-sm font-mono break-all",children:l})}),e.jsxs(r,{onClick:()=>l&&P(l),className:"w-full",children:[e.jsx(t,{icon:J,size:16,strokeWidth:2,className:"mr-2"}),"Copy to Clipboard"]})]})]})})]})})}export{se as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.