import{al as $,am as V,cb as v,cs as r,an as E,r as u,bp as h,dv as I,bz as O,aD as P,aE as S,j as e,B as t,be as p,b5 as T,aR as q,b4 as s,q as g,s as x,bx as B,y as M,by as N}from"./index-C1DmWO_C.js";import{u as A,r as F}from"./useProjectOptions-BhlzfZPS.js";const H=$().shape({project:V().label("Project").required(),role:v().oneOf(Object.keys(r)).label("Role").required(),cloudRole:E().label("Cloud Role").required()}),_=()=>{const a=h(),[n,{isLoading:j}]=I(),{data:m=[],isLoading:b}=A(),l=O(),R={project:"",role:r.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:f,handleSubmit:w,watch:y,setValue:i,reset:c}=P({defaultValues:R,resolver:S(H),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[X,k]=y(["role","project"]),D=u.useCallback(o=>{n({projectId:o.project,projectRole:o.role,cloudRole:o.cloudRole}).unwrap().then(d=>{c({project:"",role:r.ALL,cloudRole:"",defaultRole:!1}),l.success({title:"New mapping created",content:`${o.project} -> ${o.cloudRole}`})}).catch(d=>{const L=d.response.data.errorMsg;l.error({title:"Error creating mapping",content:L})})},[n,l,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:b,onChange:o=>{i("project",o,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:X,options:F,placeholder:"pick a role",onChange:o=>{i("role",o,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(T,{width:"100%",label:"Cloud Role",...f("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...q("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(D),children:"Create new role chaining"})]})]})},z=u.memo(_),U=()=>{B(N.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(M,{title:"Create new role chaining",children:e.jsx(z,{})})]})};export{U as default};
