import{a7 as F,aj as P,cT as E,cl as v,aS as k,an as I,ao as T,a as q,r as w,j as e,E as M,aU as m,cj as O,Q as x,aH as g,ay as h,b4 as Q,az as C,aI as U,bq as _,a3 as z,a4 as B,b as i,b3 as G,b1 as H,aY as R,aZ as W}from"./index-ea7817a2.js";import{b as Y}from"./secrets.selectors-ddf84833.js";import{S as a}from"./secrets-9b018a52.js";const Z=F().shape({name:P.label("Name"),secret:E.required().label("Secret"),project:v.when("visibility",{is:a.project,then:v.required().label("Project")})}),A=({isLoading:c,initialData:s,onSubmit:l})=>{var S;const b=k(),{control:p,handleSubmit:j,formState:{errors:n},register:d,watch:u}=I({defaultValues:{name:s==null?void 0:s.name,secret:s==null?void 0:s.secret,visibility:s==null?void 0:s.visibility,project:(S=s==null?void 0:s.project)==null?void 0:S.projectName},resolver:T(Z),shouldUnregister:!1}),f=u("visibility"),{currentData:o=[]}=q(void 0,{skip:f!==a.project}),y=w.useMemo(()=>o==null?void 0:o.reduce((r,t)=>(r[t.projectName]=t.projectId,r),{}),[o]),V=r=>{const t={...r,project:y[r.project]};l(t)};return e.jsx(M,{actions:e.jsx(m,{mr:"-15px",href:"https://docs.hopsworks.ai/".concat(O.docsVersion,"/user_guides/projects/secrets/create_secret/"),external:!0,target:"_blank",intent:"inline",children:"documentation ↗"}),title:"Create new secret",children:e.jsxs(x,{flexDirection:"column",children:[e.jsx(x,{mb:"20px",children:e.jsx(g,{...d("name"),label:"Name",disabled:c,placeholder:"name of the secret",...h("name",n)})}),e.jsx(g,{...d("secret"),label:"Secret",type:"textarea",width:"100%",disabled:c,placeholder:"value of the secret",...h("secret",n)}),e.jsx(Q,{mt:"20px",mb:"8px",children:"Visibility"}),e.jsx(C,{control:p,name:"visibility",defaultValue:(s==null?void 0:s.visibility)||a.private,render:({field:{onChange:r,value:t}})=>e.jsx(U,{flexDirection:"row",mr:"20px",disabled:c,value:t,options:Object.values(a),onChange:r})}),f===a.project&&e.jsxs(e.Fragment,{children:[e.jsx(C,{control:p,name:"project",render:({field:{onChange:r,value:t}})=>e.jsx(_,{mt:"20px",mb:"20px",disabled:c||!((o==null?void 0:o.length)>0),noDataMessage:"no projects available",placeholder:"project",label:"",listWidth:"100%",hasPlaceholder:!0,options:Object.keys(y),value:t?[t]:[],onChange:([N])=>r(N),...h("project",n)})}),e.jsx(z,{content:"Members of the project will be able to access the secrets",type:B.warning})]}),e.jsxs(x,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(m,{mr:"20px",type:"button",disabled:c,intent:"secondary",onClick:()=>b(i.account.secrets.list),children:"Back"}),e.jsx(m,{disabled:c,intent:"primary",onClick:j(V),children:"Create secret"})]})]})})},$=()=>{const c=G(Y),s=H(),l=k();R(W.createSecret);const b=w.useCallback(async({name:p,secret:j,visibility:n,project:d})=>{const u={name:p,secret:j,visibility:n.toUpperCase(),...n===a.project&&{scope:d}};await s.secrets.create({data:u}),l(i.account.secrets.list)},[s.secrets,l]);return e.jsxs(e.Fragment,{children:[e.jsx(m,{mb:"15px",ml:"-12px",intent:"inline",alignSelf:"flex-start",onClick:()=>l(i.account.secrets.list),children:"⇽ all secrets"}),e.jsx(A,{isLoading:c,onSubmit:b})]})};export{$ as default};
