import{r as d,j as e}from"./vendor-react-wBh_31cN.js";import{j as z,u as g}from"./vendor-redux-CJZrIb6x.js";import{aq as F,R as f,G as u,r as C,aw as P,D as $,z as q,B as A,C as G,F as M}from"./index-dNe6i2rS.js";import{T as w}from"./tooltip-DFFgUYh6.js";import{C as N,a as b,b as y,c as D}from"./card-BeQtvmcJ.js";import{C as T}from"./card-link-4kqDd55h.js";import{C as J}from"./code-BwgxKro-.js";import{V as p}from"./value-7N0Keti9.js";import{I as L}from"./icon-button-BZeFL7T7.js";import{T as Q,a as U,b as S,c as n,d as X,e as o}from"./table-a0YeQrHM.js";import{C as K}from"./confirmation-dialog-C7dws5K4.js";import{g as O}from"./getHopsDoc-B_Rq_F9V.js";import{s as W,a as Y}from"./secrets.selectors-CBieCzvZ.js";import{u as Z}from"./useTitle-DQo_L6Ox.js";import{t as ee}from"./titles-CzjGGAB3.js";import{a as se}from"./index-DURBtSjL.js";import{S as te}from"./secrets-Bl4_kNye.js";import{u as re}from"./vendor-router-D1GqFWiT.js";import{X as ae,ai as ie}from"./vendor-icons-BUUmD6ht.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./input-DFI7JniT.js";import"./label-gPWmc6ow.js";import"./useCopyToClipboard-DfzwgDFE.js";import"./useNotifier-BGMn6HaH.js";import"./notifications-5miqOdlG.js";import"./toast-wiGcevcF.js";const ne=(r,a,s)=>{var l;if(r===te.private.toUpperCase()||!s.length)return r.toLowerCase();const c=((l=s.find(i=>i.projectId===a))==null?void 0:l.projectName)||"";return`${r.toLowerCase()}(${c})`},Ie=()=>{const r=re(),a=z(),[s,c]=d.useState(),[l,i]=d.useState(!1),[R,x]=d.useState(!1),k=g(W),m=g(Y).sort((t,h)=>t.name.localeCompare(h.name));Z(ee.secrets);const{currentData:v=[],isLoading:B}=se(),V=t=>{c(t),x(!0)},H=t=>{c(t),i(!0)},I=async()=>{s&&(await a.secrets.delete(s.name),a.secrets.fetchAll(),i(!1))};return d.useEffect(()=>{a.secrets.fetchAll()},[a]),k||B?e.jsx(F,{}):m.length?e.jsxs(e.Fragment,{children:[e.jsxs(N,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between",children:[e.jsx(y,{children:"Secrets"}),e.jsx(T,{href:O("/user_guides/projects/secrets/create_secret/"),external:!0,children:"documentation"})]}),e.jsxs(D,{children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(p,{primary:!0,children:m.length}),e.jsx(p,{children:m.length>1?"Secrets":"Secret"})]}),e.jsx(u,{onClick:()=>r(C.account.secrets.create),children:"New Secret"})]}),e.jsxs(Q,{children:[e.jsx(U,{children:e.jsxs(S,{children:[e.jsx(n,{children:"Name"}),e.jsx(n,{children:"Visibility"}),e.jsx(n,{children:"Creation"}),e.jsx(n,{className:"w-10"}),e.jsx(n,{className:"w-10"})]})}),e.jsx(X,{children:m.map(({name:t,visibility:h,scope:E,addedOn:_,secret:j})=>e.jsxs(S,{children:[e.jsx(o,{className:"whitespace-nowrap",children:e.jsx(p,{children:t})}),e.jsx(o,{className:"whitespace-nowrap",children:e.jsx(p,{children:ne(h,+E,v)})}),e.jsx(o,{className:"whitespace-nowrap",children:e.jsx(f,{gray:!0,children:P(new Date(_),"yyyy-MM-dd")})}),e.jsx(o,{className:"whitespace-nowrap",children:e.jsx(w,{content:"Read",children:e.jsx(L,{"aria-label":"Read",disabled:!j,onClick:()=>V({name:t,secret:j}),children:e.jsx(ae,{className:"size-3.5"})})})}),e.jsx(o,{className:"whitespace-nowrap",children:e.jsx(w,{content:"Delete",children:e.jsx(L,{"aria-label":"Delete",onClick:()=>H({name:t,secret:j}),children:e.jsx(ie,{className:"size-3.5"})})})})]},t))})]})]})]}),e.jsx($,{open:R,onOpenChange:t=>!t&&x(!1),children:e.jsxs(q,{className:"max-w-sm",showCloseButton:!1,children:[e.jsx(A,{children:e.jsx(G,{children:"Read the secret"})}),e.jsx(J,{copyButton:!0,content:(s==null?void 0:s.secret)||"",title:s==null?void 0:s.name}),e.jsx(M,{children:e.jsx(u,{variant:"outline",onClick:()=>x(!1),children:"Done"})})]})}),e.jsx(K,{open:l,onOpenChange:i,className:"max-w-sm",title:`Delete secret ${(s==null?void 0:s.name)??""}`,description:"Once you delete a secret, there is no going back. Please be certain.",confirmLabel:"Delete secret",confirmVariant:"destructive",requireTypedConfirm:!0,onConfirm:I})]}):e.jsxs(N,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between",children:[e.jsx(y,{children:"Secrets"}),e.jsx(T,{href:O("/user_guides/projects/secrets/create_secret/"),external:!0,children:"documentation"})]}),e.jsx(D,{children:e.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[e.jsx(f,{className:"text-lg",bold:!0,children:"No secrets defined"}),e.jsx(f,{children:"Secrets let you store sensitive data in order to access to it later from a Jupyter notebook for instance"}),e.jsx(u,{className:"mt-4",onClick:()=>r(C.account.secrets.create),children:"New Secret"})]})})]})};export{Ie as default};
