import{r as i,j as e}from"./@radix-B1sy0Lhr.js";import{a as p,u as D,S as v,E as S}from"./SecretTooltip-CErfhVgF.js";import{b as f,h as b}from"./@tanstack-Dwlisomv.js";import{az as C,aA as N,aB as E,I as j,aD as w,aE as k,B as h,aP as T,bb as A,L as K,M as O,N as V,O as B,d as L,aH as z,aI as I,Y as F,$ as P,bc as Q,r as R,k as q,X as H}from"./index-CO6UN3UX.js";import{S as M}from"./eye-BXcQevds.js";import{S as _}from"./key-icon-BiV171aI.js";import{S as $}from"./trash-D9LA4VFD.js";import{A as U}from"./AlertDialogDropdownItem-BpLj419i.js";import{a as X}from"./@react-router-CHjLNlgw.js";import"./plus-DOrkJCmy.js";import"./zod-D48zuELD.js";import"./index.esm-SBF9nn_P.js";import"./CodeSnippet-B7Wd4R8u.js";import"./info-CI2szPUG.js";import"./@reactflow-gbyyU3kq.js";function Y({secretId:t,keyName:s}){const{data:a,isLoading:r,isError:u}=f({...p.secretDetail(t)}),l=b(),{mutate:c}=D({onError(d){T(d)&&A({status:"error",emphasis:"subtle",description:d.message,rounded:!0})},onSuccess(){l.invalidateQueries({queryKey:["secrets"]}),l.invalidateQueries({queryKey:["secretDetail",t]})}}),[n,m]=i.useState(""),x=()=>{var d;if(a){const g={...(d=a.body)==null?void 0:d.values};delete g[s];const y={name:a.name,values:g};c({id:t,body:y})}};function o(d){m(d.target.value)}return r?e.jsx("div",{children:"Loading..."}):u?e.jsx("div",{children:"Error loading secret details"}):e.jsxs(C,{children:[e.jsx(N,{children:e.jsx(E,{children:"Delete Key"})}),e.jsxs("div",{className:"gap-5 p-5",children:[e.jsx("p",{className:"text-text-md text-theme-text-secondary",children:"Are you sure you want to delete this key?"}),e.jsx("p",{className:"text-text-md text-theme-text-secondary",children:"This action cannot be undone."}),e.jsx("h3",{className:"font-inter text-sm mb-1 mt-4 text-left font-medium leading-5",children:"Please type DELETE to confirm"}),e.jsx(j,{name:"key",onChange:o,className:"w-full",required:!0,value:n})]}),e.jsxs(w,{className:"gap-[10px]",children:[e.jsx(k,{asChild:!0,children:e.jsx(h,{size:"sm",intent:"secondary",children:"Cancel"})}),e.jsx(h,{intent:"danger",type:"button",onClick:x,disabled:n!=="DELETE",children:"Delete"})]})]})}function G({secretId:t,keyName:s}){const[a,r]=i.useState(!1),[u,l]=i.useState(!1),c=i.useRef(null),n=i.useRef(null);function m(){n.current=c.current}function x(o){if(o===!1){r(!1),setTimeout(()=>{l(o)},200);return}l(o)}return e.jsxs(K,{onOpenChange:r,open:a,children:[e.jsx(O,{ref:c,children:e.jsx(V,{className:"h-4 w-4 fill-theme-text-tertiary"})}),e.jsx(B,{hidden:u,onCloseAutoFocus:o=>{n.current&&(n.current.focus(),n.current=null,o.preventDefault())},align:"end",sideOffset:7,children:e.jsx(U,{onSelect:m,onOpenChange:x,triggerChildren:"Delete ",icon:e.jsx($,{}),children:e.jsx(Y,{secretId:t,keyName:s})})})]})}const J=({value:t})=>{const[s,a]=i.useState(!1),r=typeof t=="string"?t:"",u="•".repeat(r.length);return e.jsxs("div",{className:"flex  items-center gap-2 space-x-2",children:[e.jsx(M,{onClick:()=>a(!s),className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:s?r:u})]})};function W(t,s){return[{id:"key",header:"Key",accessorKey:"key",cell:({row:a})=>{const r=`from zenml.client import Client
secret = Client().get_secret("${s}")
	  
# '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 items-center space-x-2",children:[e.jsx(_,{className:"h-5 w-5 flex-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("span",{className:"text-text-md font-semibold text-theme-text-primary",children:a.original.key}),e.jsx(v,{code:r})]})})})]})}},{id:"value",header:"Value",accessorKey:"value",cell:({row:a})=>e.jsx(J,{value:a.getValue("value")})},{id:"actions",header:"",cell:({row:a})=>e.jsx(G,{secretId:t,keyName:a.original.key})}]}function Z({secretId:t}){var c;const[s,a]=i.useState(""),r=f({...p.secretDetail(t)});if(r.isPending)return e.jsx(L,{className:"h-[200px] w-full"});if(r.isError)return e.jsx("div",{children:r.error.message});const l=Object.entries(((c=r.data.body)==null?void 0:c.values)||{}).map(([n,m])=>({key:n,value:m})).filter(n=>n.key.toLowerCase().includes(s.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(j,{type:"text",placeholder:"Search Keys...",value:s,onChange:n=>a(n.target.value),inputSize:"md"}),e.jsxs(z,{children:[e.jsx(I,{asChild:!0,children:e.jsx(h,{size:"sm",intent:"primary",children:"Edit Keys"})}),e.jsx(S,{secretId:t,isSecretNameEditable:!1,dialogTitle:"Edit keys"})]})]}),e.jsx("div",{className:"w-full",children:e.jsx(F,{columns:W(t,r.data.name),data:l})})]})}function ee(t){const{setBreadcrumbs:s}=P();i.useEffect(()=>{t&&s([...Q,{label:t.name,href:R.settings.secrets.detail(t.id)}])},[t,s])}function fe(){const{secretId:t}=X(),{data:s}=f({...p.secretDetail(t||"")});return ee(s),e.jsx(e.Fragment,{children:e.jsxs(q,{className:"space-y-5 p-5",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-text-xl font-semibold",children:s==null?void 0:s.name}),e.jsxs("div",{className:"group/copybutton flex items-center space-x-1",children:[e.jsx("div",{className:"text-theme-text-secondary",children:t==null?void 0:t.slice(0,8)}),e.jsx(H,{copyText:t})]})]}),e.jsx(Z,{secretId:t||""})]})})}export{fe as default};
