import{bo as w,aC as F,aD as V,ar as $,a as E,r as k,bt as I,j as e,b as O,$ as u,b2 as v,aN as S,bF as P,aO as g,be as _,bd as q,ch as M,a3 as T,a5 as U,b1 as p,q as x,c4 as H,au as B,cu as C,df as G,aE as J,k as K,bI as Q,bH as R,bw as X,bx as z}from"./index-46ma1THH.js";import{b as A}from"./secrets.selectors-CBieCzvZ.js";import{S as l}from"./secrets-Bl4_kNye.js";const W=$().shape({name:J.label("Name"),secret:G.required().label("Secret"),project:C.when("visibility",{is:l.project,then:K(C.required().label("Project"))}),visibility:B()}),Y=({isLoading:t,initialData:s,onSubmit:n})=>{var y;const m=w(),{control:b,handleSubmit:i,formState:{errors:a},register:d,watch:j}=F({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(W),shouldUnregister:!1}),h=j("visibility"),{currentData:o=[]}=E(void 0,{skip:h!==l.project}),f=k.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:H("/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",...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(P,{mt:"20px",mb:"8px",children:"Visibility"}),e.jsx(g,{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(g,{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=w();X(z.createSecret);const m=k.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};
