import{aM as u,aQ as j,aJ as e,r as o}from"./@ui-core-DKdciH1Z.js";import{a as m,u as f,S as y,E as g}from"./SecretTooltip-CTdJeKq2.js";import{L as D,Q as v,R as S,bC as b,c7 as N,V as C,W as w,X as k,Y as E,Z as T,O as B,e as K,I as V,bu as O,bv as A,B as Q,a8 as L,a9 as M,c8 as F,r as q,k as z,a6 as I}from"./index-D7KLAbvI.js";import{S as P}from"./eye-0EFEzbgA.js";import{S as _}from"./key-icon-DOZahMub.js";import{A as R}from"./action-cell-CsLz-mf4.js";import{a as $}from"./@react-router-DaIuhn3X.js";import"./@zod-DKyD3xVW.js";import"./CodeSnippet-Dwuwo3ZI.js";import"./@reactflow-CJzATMj6.js";import"./@monaco-editor-CSMpaClf.js";function J({secretId:s,keyName:t,open:r,setOpen:a}){const{data:l,isLoading:d,isError:i}=u({...m.secretDetail(s)}),c=j(),{mutate:x}=f({onError(n){b(n)&&N({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:r,onOpenChange:a,children:e.jsx(v,{title:"Delete Key",handleDelete:p,children:e.jsxs(S,{children:[e.jsx("p",{children:"Are you sure?"}),e.jsx("p",{children:"This action cannot be undone."})]})})})}function U({secretId:s,keyName:t}){const[r,a]=o.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(J,{secretId:s,keyName:t,open:r,setOpen:a}),e.jsxs(C,{children:[e.jsx(w,{asChild:!0,children:e.jsx(k,{children:e.jsx("span",{className:"sr-only",children:"Open secret key actions"})})}),e.jsx(E,{align:"end",sideOffset:7,children:e.jsxs(T,{onSelect:()=>a(!0),className:"cursor-pointer space-x-2",children:[e.jsx(B,{className:"h-3 w-3 fill-neutral-400"}),e.jsx("p",{children:"Delete"})]})})]})]})}const W=({value:s})=>{const[t,r]=o.useState(!1),a=typeof s=="string"?s:"",l="•".repeat(a.length);return e.jsxs("div",{className:"flex items-center gap-2 space-x-2",children:[e.jsx(P,{onClick:()=>r(!t),className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:t?a:l})]})};function X(s,t){return[{id:"key",header:"Key",accessorKey:"key",cell:({row:r})=>{const a=`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["${r.original.key}"]
	  `;return e.jsxs("div",{className:"flex min-w-[10rem] items-center space-x-2",children:[e.jsx(_,{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:r.original.key})}),e.jsx(y,{code:a})]})})})]})}},{id:"value",header:"Value",accessorKey:"value",cell:({row:r})=>e.jsx(W,{value:r.getValue("value")})},{id:"actions",header:"",cell:({row:r})=>e.jsx(R,{children:e.jsx(U,{secretId:s,keyName:r.original.key})})}]}function Y({secretId:s}){const[t,r]=o.useState(""),a=u({...m.secretDetail(s)});if(a.isPending)return e.jsx(K,{className:"h-[200px] w-full"});if(a.isError)return e.jsx("div",{children:a.error.message});const d=Object.entries(a.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(V,{type:"text",placeholder:"Search Keys...",value:t,onChange:i=>r(i.target.value),inputSize:"md"}),e.jsxs(O,{children:[e.jsx(A,{asChild:!0,children:e.jsx(Q,{size:"sm",intent:"primary",children:"Edit Keys"})}),e.jsx(g,{secretId:s,isSecretNameEditable:!1,dialogTitle:"Edit keys"})]})]}),e.jsx("div",{className:"w-full",children:e.jsx(L,{columns:X(s,a.data.name),data:d})})]})}function Z(s){const{setBreadcrumbs:t}=M();o.useEffect(()=>{s&&t([...F,{label:s.name,href:q.settings.secrets.detail(s.id)}])},[s,t])}function oe(){const{secretId:s}=$(),{data:t}=u({...m.secretDetail(s||"")});return Z(t),e.jsx(e.Fragment,{children:e.jsxs(z,{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(I,{copyText:s})]})]}),e.jsx(Y,{secretId:s||""})]})})}export{oe as default};
