import{r as u,bo as h,dN as $,bz as O,dO as l,aC as S,aD as V,ar as v,j as e,a as t,bd as p,aH as E,aY as I,aJ as s,s as g,t as j,au as N,cc as M,av as P,bx as T,by as q,W as A}from"./index-_eM6l4Nf.js";import{u as F,r as H}from"./useProjectOptions-Drz85yrF.js";const B=v().shape({project:P().label("Project").required(),role:M().oneOf(Object.keys(l)).label("Role").required(),cloudRole:N().label("Cloud Role").required()}),J=()=>{const a=h(),[i,{isLoading:x}]=$(),{data:m=[],isLoading:R}=F(),r=O(),C={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:b},register:f,handleSubmit:w,watch:y,setValue:n,reset:c}=S({defaultValues:C,resolver:V(B),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[X,k]=y(["role","project"]),D=u.useCallback(o=>{i({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})})},[i,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:k,options:m,placeholder:"pick a project",isLoading:R,onChange:o=>{n("project",o,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:X,options:H,placeholder:"pick a role",onChange:o=>{n("role",o,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(E,{width:"100%",label:"Cloud Role",...f("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...I("cloudRole",b)})}),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(D),children:"Create new role chaining"})]})]})},W=u.memo(J),G=()=>{T(q.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(A,{title:"Create new role chaining",children:e.jsx(W,{})})]})};export{G as default};
