import{r as u,bo as h,dN as L,by as N,dO as l,aC as O,aD as S,ar as V,j as e,$ as t,bd as p,b2 as v,aN as I,b1 as s,o as g,q as x,au as q,cb as E,av as M,bw as P,bx as T,b as A}from"./index-46ma1THH.js";import{u as F,r as _}from"./useProjectOptions-Cg26SvBL.js";const B=V().shape({project:M().label("Project").required(),role:E().oneOf(Object.keys(l)).label("Role").required(),cloudRole:q().label("Cloud Role").required()}),H=()=>{const a=h(),[i,{isLoading:j}]=L(),{data:m=[],isLoading:b}=F(),r=N(),R={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:f,handleSubmit:w,watch:X,setValue:n,reset:c}=O({defaultValues:R,resolver:S(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(v,{width:"100%",label:"Cloud Role",...f("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(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),z=()=>{P(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{z as default};
