import{K as e,Kt as t,Nt as n,Pt as r,Ut as i,Vt as a,Zt as o,nn as s}from"./branding-B7dW-jsD.js";import{t as c}from"./createLucideIcon-DRi237xT.js";import{t as l}from"./plus-DD2vE6vi.js";import{t as u}from"./trash-2-iyhkghAR.js";import{t as d}from"./HeaderApp-Aqs89_qS.js";import{t as f}from"./use-document-meta-Ds8yu_o4.js";import{t as p}from"./badge-S6iHGjk-.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./table-DLldwgmx.js";import{a as b,i as x,n as S,o as C,r as w,t as T}from"./dialog-CkuKrUJQ.js";import{t as E}from"./api-toast-D3el9g6G.js";import{n as D}from"./actions-7uV_Ky2Y.js";var O=c(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),k=s(o(),1),A=n();async function j(){return{apiKeys:(await r.get(`/api-keys`)).data}}var M={workflows_read:`Workflows Read`,runs_read:`Runs Read`,runs_write:`Runs Write`,runs_manage:`Runs Manage`,stats_read:`Stats Read`,admin:`Admin`};function N(e){return new Date(e).toLocaleDateString(`fr-FR`,{day:`2-digit`,month:`short`,year:`numeric`})}function P(){let{apiKeys:n}=a(),r=i(),o=t(),[s,c]=(0,k.useState)(null),[j,P]=(0,k.useState)(null);f({title:`API Keys`,description:`Manage your API keys for programmatic access.`});function F(e,t){P(null),c(e),E(D(e),{loading:`Deleting ${t}...`,success:`${t} deleted`}).then(()=>o.revalidate()).catch(()=>{}).finally(()=>c(null))}return(0,A.jsxs)(d,{title:`API Keys`,description:`Manage your API keys for programmatic access.`,titleItem:(0,A.jsxs)(e,{onClick:()=>r(`/api-keys/new`),children:[(0,A.jsx)(l,{}),`New API Key`]}),children:[(0,A.jsx)(`div`,{className:`space-y-6`,children:n.length===0?(0,A.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-4 py-16 text-center border border-dashed rounded-[var(--radius)] bg-muted/20`,children:[(0,A.jsx)(O,{className:`size-10 text-muted-foreground/40`,"aria-hidden":`true`}),(0,A.jsxs)(`div`,{className:`space-y-1`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`No API keys yet`}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Create an API key to access Ironflow programmatically.`})]}),(0,A.jsxs)(e,{onClick:()=>r(`/api-keys/new`),children:[(0,A.jsx)(l,{}),`New API Key`]})]}):(0,A.jsx)(`div`,{className:`rounded-[var(--radius)] border`,children:(0,A.jsxs)(y,{children:[(0,A.jsx)(m,{children:(0,A.jsxs)(_,{children:[(0,A.jsx)(h,{children:`Name`}),(0,A.jsx)(h,{children:`Prefix`}),(0,A.jsx)(h,{children:`Scopes`}),(0,A.jsx)(h,{children:`Status`}),(0,A.jsx)(h,{children:`Last Used`}),(0,A.jsx)(h,{children:`Created`}),(0,A.jsx)(h,{className:`w-12`})]})}),(0,A.jsx)(g,{children:n.map(t=>(0,A.jsxs)(_,{children:[(0,A.jsx)(v,{className:`font-medium`,children:t.name}),(0,A.jsx)(v,{children:(0,A.jsxs)(`code`,{className:`font-mono text-xs bg-muted px-1.5 py-0.5 rounded-[var(--radius-sm)]`,children:[t.key_prefix,`...`]})}),(0,A.jsx)(v,{className:`align-top`,children:(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1 max-w-[240px]`,children:t.scopes.map(e=>(0,A.jsx)(p,{variant:`secondary`,className:`text-xs`,children:M[e]??e},e))})}),(0,A.jsx)(v,{children:t.is_active?(0,A.jsx)(p,{variant:`outline`,className:`bg-success/10 text-success border-success/20 text-xs`,children:`Active`}):(0,A.jsx)(p,{variant:`secondary`,className:`text-xs`,children:`Disabled`})}),(0,A.jsx)(v,{className:`text-xs text-muted-foreground tabular-nums`,children:t.last_used_at?N(t.last_used_at):(0,A.jsx)(`span`,{className:`italic text-muted-foreground/60`,children:`Never`})}),(0,A.jsx)(v,{className:`text-xs text-muted-foreground tabular-nums`,children:N(t.created_at)}),(0,A.jsx)(v,{children:(0,A.jsx)(e,{variant:`ghost`,size:`icon-sm`,"aria-label":`Delete ${t.name}`,disabled:s===t.id,onClick:()=>P({id:t.id,name:t.name}),children:(0,A.jsx)(u,{className:`text-destructive`})})})]},t.id))})]})})}),(0,A.jsx)(T,{open:j!==null,onOpenChange:e=>{e||P(null)},children:(0,A.jsxs)(S,{children:[(0,A.jsxs)(b,{children:[(0,A.jsx)(C,{children:`Delete API key`}),(0,A.jsxs)(w,{children:[`Are you sure you want to delete`,` `,(0,A.jsx)(`span`,{className:`font-mono font-medium text-foreground`,children:j?.name}),`? Any integrations using this key will immediately lose access. This action cannot be undone.`]})]}),(0,A.jsxs)(x,{children:[(0,A.jsx)(e,{variant:`outline`,onClick:()=>P(null),children:`Cancel`}),(0,A.jsx)(e,{variant:`destructive`,disabled:j!==null&&s===j.id,onClick:()=>{j&&F(j.id,j.name)},children:`Delete`})]})]})})]})}export{P as Component,j as loader};