import{bo as k,aC as V,aD as $,ar as F,a as E,r as w,bu as I,j as e,b as O,$ as u,b2 as v,aN as g,bG as P,aO as S,be as _,bd as q,ci as M,a3 as T,a5 as U,b1 as p,q as x,c5 as G,au as J,cv as C,dg as B,aE as H,k as K,bJ as Q,bI as R,bx as X,by as z}from"./index-ljTaFLaB.js";import{b as A}from"./secrets.selectors-CBieCzvZ.js";import{S as l}from"./secrets-Bl4_kNye.js";const W=F().shape({name:H.label("Name"),secret:B.required().label("Secret"),project:C.when("visibility",{is:l.project,then:K(C.required().label("Project"))}),visibility:J()}),Y=({isLoading:t,initialData:s,onSubmit:n})=>{var y;const m=k(),{control:b,handleSubmit:i,formState:{errors:a},register:d,watch:j}=V({defaultValues:{name:s==null?void 0:s.name,secret:s==null?void 0:s.secret,visibility:s==null?void 0:s.visibility,project:(y=s==null?void 0:s.project)==null?void 0:y.projectName},resolver:$(W),shouldUnregister:!1}),h=j("visibility"),{currentData:o=[]}=E(void 0,{skip:h!==l.project}),f=w.useMemo(()=>o==null?void 0:o.reduce((r,c)=>I(c.projectName,c.projectId,r),{}),[o]),N=r=>{const c={...r,project:f[r.project]};n(c)};return e.jsx(O,{actions:e.jsx(p,{mr:"-15px",href:G("/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(v,{...d("name"),label:"Name",disabled:t,placeholder:"name of the secret",...g("name",a)})}),e.jsx(v,{...d("secret"),label:"Secret",type:"textarea",width:"100%",disabled:t,placeholder:"value of the secret",...g("secret",a)}),e.jsx(P,{mt:"20px",mb:"8px",children:"Visibility"}),e.jsx(S,{control:b,name:"visibility",defaultValue:(s==null?void 0:s.visibility)||l.private,render:({field:{onChange:r,value:c}})=>e.jsx(_,{flexDirection:"row",mr:"20px",disabled:t,value:c,options:Object.values(l),onChange:r})}),h===l.project&&e.jsxs(e.Fragment,{children:[e.jsx(S,{control:b,name:"project",render:({field:{onChange:r,value:c}})=>e.jsx(q,{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,...M("project",a)})}),e.jsx(T,{content:"Members of the project will be able to access the secrets",type:U.warning})]}),e.jsxs(u,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(p,{mr:"20px",type:"button",disabled:t,intent:"secondary",onClick:()=>m(x.account.secrets.list),children:"Back"}),e.jsx(p,{disabled:t,intent:"primary",onClick:i(N),children:"Create secret"})]})]})})},ee=()=>{const t=Q(A),s=R(),n=k();X(z.createSecret);const m=w.useCallback(async({name:b,secret:i,visibility:a,project:d})=>{const j={name:b,secret:i,visibility:a.toUpperCase(),...a===l.project&&{scope:d}};await s.secrets.create({data:j}),n(x.account.secrets.list)},[s.secrets,n]);return e.jsxs(e.Fragment,{children:[e.jsx(p,{mb:"15px",ml:"-12px",intent:"inline",alignSelf:"flex-start",onClick:()=>n(x.account.secrets.list),children:"⇽ all secrets"}),e.jsx(Y,{isLoading:t,onSubmit:m})]})};export{ee as default};
