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