import{a7 as S,a8 as T,bI as V,fA as l,a9 as $,r as u,aR as h,fE as E,aZ as I,am as O,an as A,j as e,a as t,bf as p,aG as M,ax as N,aT as s,g,e as j,aX as P,K as q,aY as v}from"./index-d6499a22.js";import{u as F}from"./useProjectOptions-37a90d51.js";import{r as B}from"./iamRoleUtils-0d5d3309.js";const G=S().shape({project:T().label("Project").required(),role:V().oneOf(Object.keys(l)).label("Role").required(),cloudRole:$().label("Cloud Role").required()}),K=()=>{const a=h(),[n,{isLoading:x}]=E(),{data:m=[],isLoading:R}=F(),r=I(),f={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:b,handleSubmit:w,watch:X,setValue:i,reset:c}=O({defaultValues:f,resolver:A(G),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[k,y]=X(["role","project"]),D=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",value:y,options:m,placeholder:"pick a project",disabled:R,onChange:o=>{i("project",o.key,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:k,options:B,placeholder:"pick a role",onChange:o=>{i("role",o.key,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(M,{width:"100%",label:"Cloud Role",...b("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(j.settings.iamRoleChaining.list)),children:"Back"}),e.jsx(s,{type:"button",isLoading:x,onClick:w(D),children:"Create new role chaining"})]})]})},_=u.memo(K),Y=()=>{P(v.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(q,{title:"Create new role chaining",children:e.jsx(_,{})})]})};export{Y as default};
