import{ae as $,af as D,bF as q,bX as l,ag as v,r as u,b4 as h,cY as E,bd as O,au as P,av as S,j as e,d as t,aQ as p,aR as F,aE as I,b6 as s,o as g,q as j,bb as M,Q as N,bc as T}from"./index-CK33qGU_.js";import{u as A,r as Q}from"./useProjectOptions-CUI0IhzU.js";const B=$().shape({project:D().label("Project").required(),role:q().oneOf(Object.keys(l)).label("Role").required(),cloudRole:v().label("Cloud Role").required()}),H=()=>{const a=h(),[n,{isLoading:x}]=E(),{data:m=[],isLoading:R}=A(),r=O(),b={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:C},register:f,handleSubmit:w,watch:X,setValue:i,reset:c}=P({defaultValues:b,resolver:S(B),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[k,y]=X(["role","project"]),L=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 V=d.response.data.errorMsg;r.error({title:"Error creating mapping",content:V})})},[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",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:Q,placeholder:"pick a role",onChange:o=>{i("role",o,{shouldValidate:!0,shouldDirty:!0})}})]}),e.jsx(t,{flexDirection:"row",mb:"20px",children:e.jsx(F,{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(j.settings.iamRoleChaining.list)),children:"Back"}),e.jsx(s,{type:"button",isLoading:x,onClick:w(L),children:"Create new role chaining"})]})]})},_=u.memo(H),U=()=>{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(j.settings.iamRoleChaining.list)),children:"<- all role chainings"}),e.jsx(N,{title:"Create new role chaining",children:e.jsx(_,{})})]})};export{U as default};
