import{a7 as F,ai as P,cQ as T,ck as v,aR as k,am as I,an as M,b as O,r as w,j as e,K as _,aT as m,ci as q,a as u,aG as g,ax as j,b3 as E,ay as C,aH as G,bp as K,a3 as Q,a4 as R,e as h,b2 as U,b0 as X,aX as B,aY as H}from"./index-d6499a22.js";import{b as W}from"./secrets.selectors-ddf84833.js";import{S as a}from"./secrets-9b018a52.js";const Y=F().shape({name:P.label("Name"),secret:T.required().label("Secret"),project:v.when("visibility",{is:a.project,then:v.required().label("Project")})}),z=({isLoading:c,initialData:s,onSubmit:l})=>{var S;const b=k(),{control:p,handleSubmit:x,formState:{errors:n},register:d,watch:i}=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:M(Y),shouldUnregister:!1}),f=i("visibility"),{currentData:o=[]}=O(void 0,{skip:f!==a.project}),y=w.useMemo(()=>o==null?void 0:o.reduce((r,t)=>(r[t.projectName]=t.projectId,r),{}),[o]),N=r=>{const t={...r,project:y[r.project]};l(t)};return e.jsx(_,{actions:e.jsx(m,{mr:"-15px",href:"https://docs.hopsworks.ai/".concat(q.docsVersion,"/user_guides/projects/secrets/create_secret/"),external:!0,target:"_blank",intent:"inline",children:"documentation ↗"}),title:"Create new secret",children:e.jsxs(u,{flexDirection:"column",children:[e.jsx(u,{mb:"20px",children:e.jsx(g,{...d("name"),label:"Name",disabled:c,placeholder:"name of the secret",...j("name",n)})}),e.jsx(g,{...d("secret"),label:"Secret",type:"textarea",width:"100%",disabled:c,placeholder:"value of the secret",...j("secret",n)}),e.jsx(E,{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(G,{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(K,{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:([V])=>r(V),...j("project",n)})}),e.jsx(Q,{content:"Members of the project will be able to access the secrets",type:R.warning})]}),e.jsxs(u,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(m,{mr:"20px",type:"button",disabled:c,intent:"secondary",onClick:()=>b(h.account.secrets.list),children:"Back"}),e.jsx(m,{disabled:c,intent:"primary",onClick:x(N),children:"Create secret"})]})]})})},Z=()=>{const c=U(W),s=X(),l=k();B(H.createSecret);const b=w.useCallback(async({name:p,secret:x,visibility:n,project:d})=>{const i={name:p,secret:x,visibility:n.toUpperCase(),...n===a.project&&{scope:d}};await s.secrets.create({data:i}),l(h.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(h.account.secrets.list),children:"⇽ all secrets"}),e.jsx(z,{isLoading:c,onSubmit:b})]})};export{Z as default};
