import{j as e}from"./@radix-D8tIKeo-.js";import{a as u,u as f,S as j,E as y}from"./SecretTooltip-D-tw2siE.js";import{b as m,h as g}from"./@tanstack-nMqraTcu.js";import{J as D,bs as v,bX as S,N as b,O as N,Q as C,R as k,U as w,e as E,I as T,bk as B,bl as K,B as O,a4 as V,a5 as A,bY as Q,r as F,k as L,a1 as M}from"./index-B44sgOyQ.js";import{a as o}from"./@monaco-editor-CuNQBT0l.js";import{S as q}from"./eye-CuzpINsY.js";import{S as z}from"./key-icon-Ck8DbaN1.js";import{A as I}from"./action-cell-BgyPfYXo.js";import{S as P}from"./trash-Dp8wQrEE.js";import{D as _,a as R}from"./DeleteAlertDialog-DbZA_NGz.js";import{a as U}from"./@react-router-D1ODL_Ub.js";import"./@elkjs-CmhuJAjY.js";import"./plus-BjxzjZ9E.js";import"./@zod-2qqdh1cM.js";import"./CodeSnippet-WWMTzt1F.js";import"./@reactflow-DgowYF6H.js";function $({secretId:s,keyName:t,open:a,setOpen:r}){const{data:l,isLoading:d,isError:i}=m({...u.secretDetail(s)}),c=g(),{mutate:x}=f({onError(n){v(n)&&S({status:"error",emphasis:"subtle",description:n.message,rounded:!0})},onSuccess(){c.invalidateQueries({queryKey:["secrets"]}),c.invalidateQueries({queryKey:["secretDetail",s]})}}),p=()=>{if(l){const n={...l.body?.values};delete n[t];const h={name:l.name,values:n};x({id:s,body:h})}};return d?e.jsx("div",{children:"Loading..."}):i?e.jsx("div",{children:"Error loading secret details"}):e.jsx(D,{open:a,onOpenChange:r,children:e.jsx(_,{title:"Delete Key",handleDelete:p,children:e.jsxs(R,{children:[e.jsx("p",{children:"Are you sure?"}),e.jsx("p",{children:"This action cannot be undone."})]})})})}function J({secretId:s,keyName:t}){const[a,r]=o.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx($,{secretId:s,keyName:t,open:a,setOpen:r}),e.jsxs(b,{children:[e.jsx(N,{asChild:!0,children:e.jsx(C,{children:e.jsx("span",{className:"sr-only",children:"Open secret key actions"})})}),e.jsx(k,{align:"end",sideOffset:7,children:e.jsxs(w,{onSelect:()=>r(!0),className:"cursor-pointer space-x-2",children:[e.jsx(P,{className:"h-3 w-3 fill-neutral-400"}),e.jsx("p",{children:"Delete"})]})})]})]})}const X=({value:s})=>{const[t,a]=o.useState(!1),r=typeof s=="string"?s:"",l="•".repeat(r.length);return e.jsxs("div",{className:"flex items-center gap-2 space-x-2",children:[e.jsx(q,{onClick:()=>a(!t),className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:t?r:l})]})};function Y(s,t){return[{id:"key",header:"Key",accessorKey:"key",cell:({row:a})=>{const r=`from zenml.client import Client
secret = Client().get_secret("${t}")

# 'secret.secret_values' will contain a dictionary with all key-value pairs within your secret.
secret.secret_values["${a.original.key}"]
	  `;return e.jsxs("div",{className:"flex min-w-[10rem] items-center space-x-2",children:[e.jsx(z,{className:"h-5 w-5 shrink-0 fill-primary-400"}),e.jsx("div",{className:"flex flex-col",children:e.jsx("div",{className:"flex items-center space-x-1",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("div",{className:"grid grid-cols-1",children:e.jsx("span",{className:"truncate text-text-md font-semibold text-theme-text-primary",children:a.original.key})}),e.jsx(j,{code:r})]})})})]})}},{id:"value",header:"Value",accessorKey:"value",cell:({row:a})=>e.jsx(X,{value:a.getValue("value")})},{id:"actions",header:"",cell:({row:a})=>e.jsx(I,{children:e.jsx(J,{secretId:s,keyName:a.original.key})})}]}function G({secretId:s}){const[t,a]=o.useState(""),r=m({...u.secretDetail(s)});if(r.isPending)return e.jsx(E,{className:"h-[200px] w-full"});if(r.isError)return e.jsx("div",{children:r.error.message});const d=Object.entries(r.data.body?.values||{}).map(([i,c])=>({key:i,value:c})).filter(i=>i.key.toLowerCase().includes(t.toLowerCase()));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-2",children:[e.jsx(T,{type:"text",placeholder:"Search Keys...",value:t,onChange:i=>a(i.target.value),inputSize:"md"}),e.jsxs(B,{children:[e.jsx(K,{asChild:!0,children:e.jsx(O,{size:"sm",intent:"primary",children:"Edit Keys"})}),e.jsx(y,{secretId:s,isSecretNameEditable:!1,dialogTitle:"Edit keys"})]})]}),e.jsx("div",{className:"w-full",children:e.jsx(V,{columns:Y(s,r.data.name),data:d})})]})}function H(s){const{setBreadcrumbs:t}=A();o.useEffect(()=>{s&&t([...Q,{label:s.name,href:F.settings.secrets.detail(s.id)}])},[s,t])}function pe(){const{secretId:s}=U(),{data:t}=m({...u.secretDetail(s||"")});return H(t),e.jsx(e.Fragment,{children:e.jsxs(L,{className:"space-y-5 p-5",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-text-xl font-semibold",children:t?.name}),e.jsxs("div",{className:"group/copybutton flex items-center space-x-1",children:[e.jsx("div",{className:"text-theme-text-secondary",children:s?.slice(0,8)}),e.jsx(M,{copyText:s})]})]}),e.jsx(G,{secretId:s||""})]})})}export{pe as default};
