import{aj as V,ak as $,c4 as q,cn as r,al as E,r as u,bw as h,dn as M,aE as O,az as S,aA as v,j as e,B as t,bm as p,aM as A,b8 as B,aG as s,q as g,s as j,bC as I,m as N,bD as P}from"./index-dP1W1_bd.js";import{u as T,r as F}from"./useProjectOptions-FXFkYH64.js";const G=V().shape({project:$().label("Project").required(),role:q().oneOf(Object.keys(r)).label("Role").required(),cloudRole:E().label("Cloud Role").required()}),H=()=>{const a=h(),[n,{isLoading:x}]=M(),{data:m=[],isLoading:R}=T(),l=O(),C={project:"",role:r.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:b},register:f,handleSubmit:w,watch:X,setValue:i,reset:c}=S({defaultValues:C,resolver:v(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: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:y,options:m,placeholder:"pick a project",isLoading:R,onChange:o=>{i("project",o,{shouldValidate:!0,shouldDirty:!0})}}),e.jsx(p,{width:"180px",label:"Role",value:k,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(A,{width:"100%",label:"Cloud Role",...f("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...B("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"})]})]})},_=u.memo(H),U=()=>{I(P.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(N,{title:"Create new role chaining",children:e.jsx(_,{})})]})};export{U as default};
