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