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