import{r as u,bx as h,e4 as q,bI as D,cz as l,aA as P,aB as S,j as e,q as t,be as p,aH as V,aY as I,aJ as s,t as x,x as g,Z as M,as as O,cq as v,a0 as A,bG as E,bH as H,f as N}from"./index-DNBEEyYo.js";import{u as T,r as B}from"./useProjectOptions-D7YNvKHD.js";const F=M().shape({project:A().label("Project").required(),role:v().oneOf(Object.keys(l)).label("Role").required(),cloudRole:O().label("Cloud Role").required()}),G=()=>{const a=h(),[n,{isLoading:j}]=q(),{data:m=[],isLoading:R}=T(),r=D(),f={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:b,handleSubmit:w,watch:X,setValue:i,reset:c}=P({defaultValues:f,resolver:S(F),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[k,y]=X(["role","project"]),$=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 L=d.response.data.errorMsg;r.error({title:"Error creating mapping",content:L})})},[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",maxListHeight:"250px",value:y,options:m,placeholder:"pick a project",isLoading:R,onChange:o=>{i("project",o,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:k,options:B,placeholder:"pick a role",onChange:o=>{i("role",o,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(V,{width:"100%",label:"Cloud Role",...b("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...I("cloudRole",C)})}),e.jsxs(t,{justifyContent:"right",sx:{gap:"20px"},children:[e.jsx(s,{type:"button",intent:"secondary",onClick:()=>a(x(g.settings.iamRoleChaining.list)),children:"Back"}),e.jsx(s,{type:"button",isLoading:j,onClick:w($),children:"Create new role chaining"})]})]})},_=u.memo(G),U=()=>{E(H.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(x(g.settings.iamRoleChaining.list)),children:"<- all role chainings"}),e.jsx(N,{title:"Create new role chaining",children:e.jsx(_,{})})]})};export{U as default};
