import{a7 as D,a8 as E,bJ as $,fG as l,a9 as L,r as u,aS as h,fK as O,a_ as P,an as I,ao as M,j as e,Q as t,bg as p,aH as N,ay as T,aU as s,c as g,b as j,aY as q,E as v,aZ as A}from"./index-ea7817a2.js";import{u as F}from"./useProjectOptions-6652bb75.js";import{r as _}from"./iamRoleUtils-7a0b61f9.js";const B=D().shape({project:E().label("Project").required(),role:$().oneOf(Object.keys(l)).label("Role").required(),cloudRole:L().label("Cloud Role").required()}),G=()=>{const a=h(),[n,{isLoading:x}]=O(),{data:m=[],isLoading:R}=F(),r=P(),f={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:b,handleSubmit:w,watch:y,setValue:i,reset:c}=I({defaultValues:f,resolver:M(B),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[k,X]=y(["role","project"]),S=u.useCallback(o=>{n({projectId:o.project,projectRole:o.role,cloudRole:o.cloudRole}).unwrap().then(d=>{c({project:"",role:l.ALL,cloudRole:"",defaultRole:!1}),r.success({title:"New mapping created",content:`${o.project} -> ${o.cloudRole}`})}).catch(d=>{const V=d.response.data.errorMsg;r.error({title:"Error creating mapping",content:V})})},[n,r,c]);return e.jsxs(t,{flexDirection:"column",children:[e.jsxs(t,{mb:"20px",sx:{gap:"20px"},children:[e.jsx(p,{width:"180px",label:"Project",value:X,options:m,placeholder:"pick a project",disabled:R,onChange:o=>{i("project",o.key,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:k,options:_,placeholder:"pick a role",onChange:o=>{i("role",o.key,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(N,{width:"100%",label:"Cloud Role",...b("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...T("cloudRole",C)})}),e.jsxs(t,{justifyContent:"right",sx:{gap:"20px"},children:[e.jsx(s,{type:"button",intent:"secondary",onClick:()=>a(g(j.settings.iamRoleChaining.list)),children:"Back"}),e.jsx(s,{type:"button",isLoading:x,onClick:w(S),children:"Create new role chaining"})]})]})},H=u.memo(G),K=()=>{q(A.iamRole);const a=h();return e.jsxs(t,{flexGrow:1,flexDirection:"column",children:[e.jsx(s,{mb:"20px",pl:"0px",width:"150px",intent:"inline",onClick:()=>a(g(j.settings.iamRoleChaining.list)),children:"<- all role chainings"}),e.jsx(v,{title:"Create new role chaining",children:e.jsx(H,{})})]})};export{K as default};
