import{al as F,aG as V,d0 as I,cx as S,k as P,an as T,bp as w,aD as $,aE as B,a as E,r as k,bv as G,j as e,y as M,b4 as m,c5 as O,B as j,b5 as g,aR as u,bG as _,aS as C,bf as q,be as R,ah as U,ai as H,s as h,bK as J,bI as K,bx as Q,by as z}from"./index-C1DmWO_C.js";import{b as A}from"./secrets.selectors-CBieCzvZ.js";import{S as a}from"./secrets-Bl4_kNye.js";const W=F().shape({name:V.label("Name"),secret:I.required().label("Secret"),project:S.when("visibility",{is:a.project,then:P(S.required().label("Project"))}),visibility:T()}),X=({isLoading:t,initialData:s,onSubmit:l})=>{var v;const d=w(),{control:p,handleSubmit:i,formState:{errors:n},register:b,watch:x}=$({defaultValues:{name:s==null?void 0:s.name,secret:s==null?void 0:s.secret,visibility:s==null?void 0:s.visibility,project:(v=s==null?void 0:s.project)==null?void 0:v.projectName},resolver:B(W),shouldUnregister:!1}),y=x("visibility"),{currentData:o=[]}=E(void 0,{skip:y!==a.project}),f=k.useMemo(()=>o==null?void 0:o.reduce((r,c)=>G(c.projectName,c.projectId,r),{}),[o]),N=r=>{const c={...r,project:f[r.project]};l(c)};return e.jsx(M,{actions:e.jsx(m,{mr:"-15px",href:O("/user_guides/projects/secrets/create_secret/"),external:!0,target:"_blank",intent:"inline",children:"documentation ↗"}),title:"Create new secret",children:e.jsxs(j,{flexDirection:"column",children:[e.jsx(j,{mb:"20px",children:e.jsx(g,{...b("name"),label:"Name",disabled:t,placeholder:"name of the secret",...u("name",n)})}),e.jsx(g,{...b("secret"),label:"Secret",type:"textarea",width:"100%",disabled:t,placeholder:"value of the secret",...u("secret",n)}),e.jsx(_,{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:c}})=>e.jsx(q,{flexDirection:"row",mr:"20px",disabled:t,value:c,options:Object.values(a),onChange:r})}),y===a.project&&e.jsxs(e.Fragment,{children:[e.jsx(C,{control:p,name:"project",render:({field:{onChange:r,value:c}})=>e.jsx(R,{my:"20px",isDisabled:t||!((o==null?void 0:o.length)>0),noDataMessage:"no projects available",placeholder:"project",options:Object.keys(f),value:c,onChange:r,...u("project",n)})}),e.jsx(U,{content:"Members of the project will be able to access the secrets",type:H.warning})]}),e.jsxs(j,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(m,{mr:"20px",type:"button",disabled:t,intent:"secondary",onClick:()=>d(h.account.secrets.list),children:"Back"}),e.jsx(m,{disabled:t,intent:"primary",onClick:i(N),children:"Create secret"})]})]})})},D=()=>{const t=J(A),s=K(),l=w();Q(z.createSecret);const d=k.useCallback(async({name:p,secret:i,visibility:n,project:b})=>{const x={name:p,secret:i,visibility:n.toUpperCase(),...n===a.project&&{scope:b}};await s.secrets.create({data:x}),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(X,{isLoading:t,onSubmit:d})]})};export{D as default};
