import{r as i,j as e}from"./@radix-C7hRs6Kx.js";import{b as p,u as D,a as v,S,E as C}from"./SecretTooltip-CePCL8kd.js";import{a as f,c as N}from"./@tanstack-CSxjHCME.js";import{as as b,aI as w,at as E,I as j,aJ as k,av as T,h,ar as K,aK as A,D as V,w as O,x as B,S as I,ai as L,aj as z,M as F,n as Q,B as R,J as q}from"./index-D2iSHVZq.js";import{S as M}from"./key-icon-DO4DPJHZ.js";import{S as P}from"./dots-horizontal-BGRJCPCs.js";import{S as H}from"./trash-BWSZ7NRK.js";import{A as _}from"./AlertDialogDropdownItem-BG7-Ki1L.js";import{a as J}from"./@react-router-CNP6g_RL.js";import"./plus-COjQg3AG.js";import"./zod-C0xYeTvL.js";import"./index.esm-D7jFlf5N.js";import"./CodeSnippet-CvI6D0wx.js";import"./@reactflow-CQi1Z1Wq.js";function $({secretId:s,keyName:r}){const{data:t,isLoading:a,isError:u}=f({...p.secretDetail(s)}),l=N(),{mutate:c}=D({onError(d){K(d)&&A({status:"error",emphasis:"subtle",description:d.message,rounded:!0})},onSuccess(){l.invalidateQueries({queryKey:["secrets"]}),l.invalidateQueries({queryKey:["secretDetail",s]})}}),[n,m]=i.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(b,{children:[e.jsx(w,{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(k,{className:"gap-[10px]",children:[e.jsx(T,{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 U({secretId:s,keyName:r}){const[t,a]=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){a(!1),setTimeout(()=>{l(o)},200);return}l(o)}return e.jsxs(V,{onOpenChange:a,open:t,children:[e.jsx(O,{ref:c,children:e.jsx(P,{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($,{secretId:s,keyName:r})})})]})}const G=({value:s})=>{const[r,t]=i.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(M,{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(G,{value:t.getValue("value")})},{id:"actions",header:"",cell:({row:t})=>e.jsx(U,{secretId:s,keyName:t.original.key})}]}function X({secretId:s}){var c;const[r,t]=i.useState(""),a=f({...p.secretDetail(s)});if(a.isPending)return e.jsx(I,{className:"h-[200px] w-full"});if(a.isError)return e.jsx("div",{children:a.error.message});const l=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(L,{children:[e.jsx(z,{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(F,{columns:W(s,a.data.name),data:l})})]})}function me(){const{secretId:s}=J(),{setCurrentBreadcrumbData:r}=Q(),{data:t}=f({...p.secretDetail(s||"")});return i.useEffect(()=>{t&&r({segment:"secretsDetail",data:{name:t.name,id:t.id}})},[t]),e.jsx(e.Fragment,{children:e.jsxs(R,{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(q,{copyText:s})]})]}),e.jsx(X,{secretId:s||""})]})})}export{me as default};
