import{bo as w,aC as V,aD as E,ar as F,b as I,r as k,bu as T,j as e,W as $,a as u,aH as v,aY as g,bG as J,aZ as S,be as M,bd as O,ci as P,a3 as _,a5 as q,aJ as p,t as x,c5 as G,au as H,cv as C,dg as U,aE as W,m as B,bJ as Q,bI as R,bx as X,by as Y}from"./index-_eM6l4Nf.js";import{b as Z}from"./secrets.selectors-CBieCzvZ.js";import{S as l}from"./secrets-Bl4_kNye.js";const z=F().shape({name:W.label("Name"),secret:U.required().label("Secret"),project:C.when("visibility",{is:l.project,then:B(C.required().label("Project"))}),visibility:H()}),A=({isLoading:t,initialData:s,onSubmit:n})=>{var f;const m=w(),{control:d,handleSubmit:i,formState:{errors:a},register:b,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:(f=s==null?void 0:s.project)==null?void 0:f.projectName},resolver:E(z),shouldUnregister:!1}),h=j("visibility"),{currentData:o=[]}=I(void 0,{skip:h!==l.project}),y=k.useMemo(()=>o==null?void 0:o.reduce((r,c)=>T(c.projectName,c.projectId,r),{}),[o]),N=r=>{const c={...r,project:y[r.project]};n(c)};return e.jsx($,{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,{...b("name"),label:"Name",disabled:t,placeholder:"name of the secret",...g("name",a)})}),e.jsx(v,{...b("secret"),label:"Secret",type:"textarea",width:"100%",disabled:t,placeholder:"value of the secret",...g("secret",a)}),e.jsx(J,{mt:"20px",mb:"8px",children:"Visibility"}),e.jsx(S,{control:d,name:"visibility",defaultValue:(s==null?void 0:s.visibility)||l.private,render:({field:{onChange:r,value:c}})=>e.jsx(M,{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:d,name:"project",render:({field:{onChange:r,value:c}})=>e.jsx(O,{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,...P("project",a)})}),e.jsx(_,{content:"Members of the project will be able to access the secrets",type:q.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(Z),s=R(),n=w();X(Y.createSecret);const m=k.useCallback(async({name:d,secret:i,visibility:a,project:b})=>{const j={name:d,secret:i,visibility:a.toUpperCase(),...a===l.project&&{scope:b}};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(A,{isLoading:t,onSubmit:m})]})};export{ee as default};
