import{aj as V,aC as F,cV as M,cs as g,h as B,al as O,bw as w,az as P,aA as T,a as _,r as k,bA as $,j as e,m as q,aG as b,c1 as A,B as x,aM as C,b8 as u,bK as E,b9 as S,bn as G,bm as I,af as K,ag as U,s as h,aL as z,aD as H,bC as Q,bD as R}from"./index-dP1W1_bd.js";import{b as J}from"./secrets.selectors-CBieCzvZ.js";import{S as n}from"./secrets-Bl4_kNye.js";const L=V().shape({name:F.label("Name"),secret:M.required().label("Secret"),project:g.when("visibility",{is:n.project,then:B(g.required().label("Project"))}),visibility:O()}),W=({isLoading:t,initialData:s,onSubmit:l})=>{var v;const d=w(),{control:p,handleSubmit:i,formState:{errors:a},register:m,watch:j}=P({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:T(L),shouldUnregister:!1}),f=j("visibility"),{currentData:o=[]}=_(void 0,{skip:f!==n.project}),y=k.useMemo(()=>o==null?void 0:o.reduce((r,c)=>$(c.projectName,c.projectId,r),{}),[o]),N=r=>{const c={...r,project:y[r.project]};l(c)};return e.jsx(q,{actions:e.jsx(b,{mr:"-15px",href:A("/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(C,{...m("name"),label:"Name",disabled:t,placeholder:"name of the secret",...u("name",a)})}),e.jsx(C,{...m("secret"),label:"Secret",type:"textarea",width:"100%",disabled:t,placeholder:"value of the secret",...u("secret",a)}),e.jsx(E,{mt:"20px",mb:"8px",children:"Visibility"}),e.jsx(S,{control:p,name:"visibility",defaultValue:(s==null?void 0:s.visibility)||n.private,render:({field:{onChange:r,value:c}})=>e.jsx(G,{flexDirection:"row",mr:"20px",disabled:t,value:c,options:Object.values(n),onChange:r})}),f===n.project&&e.jsxs(e.Fragment,{children:[e.jsx(S,{control:p,name:"project",render:({field:{onChange:r,value:c}})=>e.jsx(I,{my:"20px",isDisabled:t||!((o==null?void 0:o.length)>0),noDataMessage:"no projects available",placeholder:"project",options:Object.keys(y),value:c,onChange:r,...u("project",a)})}),e.jsx(K,{content:"Members of the project will be able to access the secrets",type:U.warning})]}),e.jsxs(x,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(b,{mr:"20px",type:"button",disabled:t,intent:"secondary",onClick:()=>d(h.account.secrets.list),children:"Back"}),e.jsx(b,{disabled:t,intent:"primary",onClick:i(N),children:"Create secret"})]})]})})},D=()=>{const t=z(J),s=H(),l=w();Q(R.createSecret);const d=k.useCallback(async({name:p,secret:i,visibility:a,project:m})=>{const j={name:p,secret:i,visibility:a.toUpperCase(),...a===n.project&&{scope:m}};await s.secrets.create({data:j}),l(h.account.secrets.list)},[s.secrets,l]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{mb:"15px",ml:"-12px",intent:"inline",alignSelf:"flex-start",onClick:()=>l(h.account.secrets.list),children:"⇽ all secrets"}),e.jsx(W,{isLoading:t,onSubmit:d})]})};export{D as default};
