import{r as l,j as e}from"./@radix-AvWw-1nd.js";import{b as p,u as D,a as v,S,E as C}from"./SecretTooltip-CHPWF0bu.js";import{a as f,c as N}from"./@tanstack-CcI3lvwB.js";import{at as b,aL as w,au as k,aM as E,av as T,I as j,aN as A,ax as K,f as h,D as O,x as V,y as L,C as B,S as z,ak as F,al as I,O as Q,o as R,B as q,L as M}from"./index-DWoLoYDY.js";import{S as P}from"./key-icon-CjwWwoOU.js";import{S as H}from"./trash-B_JgTgqd.js";import{A as _}from"./AlertDialogDropdownItem-XL2NfFgP.js";import{b as $}from"./@react-router-BUo5vhN4.js";import"./plus-CoKtHiA9.js";import"./zod-CRNUMWWg.js";import"./index.esm-cf-8NBxV.js";import"./CodeSnippet-D8ptwPjg.js";import"./@reactflow-DMaYqp8l.js";function U({secretId:s,keyName:r}){const{data:t,isLoading:a,isError:u}=f({...p.secretDetail(s)}),i=N(),{mutate:c}=D({onError(d){b(d)&&w({status:"error",emphasis:"subtle",description:d.message,rounded:!0})},onSuccess(){i.invalidateQueries({queryKey:["secrets"]}),i.invalidateQueries({queryKey:["secretDetail",s]})}}),[n,m]=l.useState(""),x=()=>{var d;if(t){const g={...(d=t.body)==null?void 0:d.values};delete g[r];const y={name:t.name,scope:"workspace",values:g};c({id:s,body:y})}};function o(d){m(d.target.value)}return a?e.jsx("div",{children:"Loading..."}):u?e.jsx("div",{children:"Error loading secret details"}):e.jsxs(k,{children:[e.jsx(E,{children:e.jsx(T,{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(A,{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:s,keyName:r}){const[t,a]=l.useState(!1),[u,i]=l.useState(!1),c=l.useRef(null),n=l.useRef(null);function m(){n.current=c.current}function x(o){if(o===!1){a(!1),setTimeout(()=>{i(o)},200);return}i(o)}return e.jsxs(O,{onOpenChange:a,open:t,children:[e.jsx(V,{ref:c,children:e.jsx(L,{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(_,{onSelect:m,onOpenChange:x,triggerChildren:"Delete ",icon:e.jsx(H,{}),children:e.jsx(U,{secretId:s,keyName:r})})})]})}const J=({value:s})=>{const[r,t]=l.useState(!1),a=typeof s=="string"?s:"",u="•".repeat(a.length);return e.jsxs("div",{className:"flex  items-center gap-2 space-x-2",children:[e.jsx(S,{onClick:()=>t(!r),className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:r?a:u})]})};function W(s,r){return[{id:"key",header:"Key",accessorKey:"key",cell:({row:t})=>{const a=`from zenml.client import Client
secret = Client().get_secret("${r}")
	  
# 'secret.secret_values' will contain a dictionary with all key-value pairs within your secret.
secret.secret_values["${t.original.key}"]
	  `;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(P,{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:t.original.key}),e.jsx(v,{code:a})]})})})]})}},{id:"value",header:"Value",accessorKey:"value",cell:({row:t})=>e.jsx(J,{value:t.getValue("value")})},{id:"actions",header:"",cell:({row:t})=>e.jsx(G,{secretId:s,keyName:t.original.key})}]}function X({secretId:s}){var c;const[r,t]=l.useState(""),a=f({...p.secretDetail(s)});if(a.isPending)return e.jsx(z,{className:"h-[200px] w-full"});if(a.isError)return e.jsx("div",{children:a.error.message});const i=Object.entries(((c=a.data.body)==null?void 0:c.values)||{}).map(([n,m])=>({key:n,value:m})).filter(n=>n.key.toLowerCase().includes(r.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:r,onChange:n=>t(n.target.value),inputSize:"md"}),e.jsxs(F,{children:[e.jsx(I,{asChild:!0,children:e.jsx(h,{size:"sm",intent:"primary",children:"Edit Keys"})}),e.jsx(C,{secretId:s,isSecretNameEditable:!1,dialogTitle:"Edit keys"})]})]}),e.jsx("div",{className:"w-full",children:e.jsx(Q,{columns:W(s,a.data.name),data:i})})]})}function ue(){const{secretId:s}=$(),{setCurrentBreadcrumbData:r}=R(),{data:t}=f({...p.secretDetail(s||"")});return l.useEffect(()=>{t&&r({segment:"secretsDetail",data:{name:t.name,id:t.id}})},[t]),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:t==null?void 0: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==null?void 0:s.slice(0,8)}),e.jsx(M,{copyText:s})]})]}),e.jsx(X,{secretId:s||""})]})})}export{ue as default};
