import{G as e,Q as t,et as n,i as r,nt as i,r as a,st as o,ut as s}from"./branding-ClCX8iZg.js";import{t as c}from"./createLucideIcon-Bj0ivoOU.js";import{t as l}from"./plus-BXvgCskW.js";import{t as u}from"./trash-2-D1mEG7Sg.js";import{t as d}from"./HeaderApp-HWu4NOgP.js";import{t as f}from"./use-document-meta-Br4UMxjt.js";import{a as p,i as m,n as h,o as g,r as _,t as v}from"./table-ziljfcNR.js";import{t as y}from"./api-toast-BFyXHsNH.js";import{t as b}from"./TimeAgo-4qtOxGXr.js";import{i as x,r as S,t as C}from"./textarea-CU-rr98-.js";import{a as w,n as T,o as E,r as D,t as O}from"./dialog-C2M01c4v.js";var k=c(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),A=s(o(),1),j=r();async function M(){return{secrets:(await e.get(`/secrets`)).data}}function N(){let{secrets:e}=t(),r=n(),o=i(),[s,c]=(0,A.useState)(null),[M,N]=(0,A.useState)(null),[P,F]=(0,A.useState)(``),[I,L]=(0,A.useState)(!1);f({title:`Secrets`,description:`Manage encrypted secrets accessible from workflows.`});function R(e){confirm(`Delete secret "${e}"? This cannot be undone.`)&&(c(e),y(S(e),{loading:`Deleting ${e}...`,success:`${e} deleted`}).then(()=>o.revalidate()).catch(()=>{}).finally(()=>c(null)))}function z(e){N(e),F(``)}function B(){N(null),F(``),L(!1)}function V(){!M||!P.trim()||(L(!0),y(x(M.key,{value:P}),{loading:`Updating secret...`,success:`Secret updated`}).then(()=>{o.revalidate(),B()}).catch(()=>{}).finally(()=>L(!1)))}return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(d,{title:`Secrets`,description:`Encrypted secrets accessible from workflows.`,titleItem:(0,j.jsxs)(a,{onClick:()=>r(`/secrets/new`),children:[(0,j.jsx)(l,{className:`h-4 w-4 mr-1`}),`New Secret`]}),children:(0,j.jsx)(`div`,{className:`space-y-6`,children:e.length===0?(0,j.jsx)(`div`,{className:`text-center py-16 text-muted-foreground border rounded-lg bg-muted/20`,children:`No secrets yet. Create one to get started.`}):(0,j.jsx)(`div`,{className:`rounded-lg border`,children:(0,j.jsxs)(v,{children:[(0,j.jsx)(p,{children:(0,j.jsxs)(g,{children:[(0,j.jsx)(m,{children:`Key`}),(0,j.jsx)(m,{children:`Created`}),(0,j.jsx)(m,{children:`Updated`}),(0,j.jsx)(m,{className:`w-16`})]})}),(0,j.jsx)(h,{children:e.map(e=>(0,j.jsxs)(g,{children:[(0,j.jsx)(_,{className:`font-medium`,children:e.key}),(0,j.jsx)(_,{children:(0,j.jsx)(b,{date:e.created_at})}),(0,j.jsx)(_,{children:(0,j.jsx)(b,{date:e.updated_at})}),(0,j.jsx)(_,{children:(0,j.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,j.jsx)(a,{variant:`ghost`,size:`icon-sm`,onClick:()=>z(e),children:(0,j.jsx)(k,{className:`h-4 w-4`})}),(0,j.jsx)(a,{variant:`ghost`,size:`icon-sm`,onClick:()=>R(e.key),disabled:s===e.key,children:(0,j.jsx)(u,{className:`h-4 w-4 text-destructive`})})]})})]},e.id))})]})})})}),(0,j.jsx)(O,{open:M!==null,onOpenChange:B,children:(0,j.jsxs)(T,{children:[(0,j.jsxs)(w,{children:[(0,j.jsx)(E,{children:`Edit Secret`}),(0,j.jsxs)(D,{children:[`Update the value for `,M?.key]})]}),(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`span`,{className:`text-sm font-medium`,children:`Key (read-only)`}),(0,j.jsx)(`div`,{className:`mt-1 px-3 py-2 bg-muted rounded text-sm`,children:M?.key})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`secret-value`,className:`text-sm font-medium`,children:`Value`}),(0,j.jsx)(C,{id:`secret-value`,placeholder:`Enter the secret value`,value:P,onChange:e=>F(e.target.value),className:`mt-1`,rows:4})]}),(0,j.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,j.jsx)(a,{variant:`outline`,onClick:B,disabled:I,children:`Cancel`}),(0,j.jsx)(a,{onClick:V,disabled:!P.trim()||I,children:I?`Saving...`:`Save`})]})]})]})})]})}export{N as Component,M as loader};