import{r as p,j as e}from"./vendor-react-wBh_31cN.js";import{C as y,a as k,b as L,c as O}from"./card-DISTA6Ay.js";import{u as $}from"./useTitle-DQo_L6Ox.js";import{t as I}from"./titles-CzjGGAB3.js";import{G as n,g as P,r as V,ar as S,as as T,bh as M,az as q}from"./index-BKr2rJhV.js";import{o as A}from"./yup-XkUC3UEH.js";import{u as B}from"./index.esm-CAGtek53.js";import{t as d}from"./toast-3g7Fh-a0.js";import{I as D}from"./input-H6_qmzms.js";import{L as a}from"./label-Dnebucx5.js";import{C as m}from"./combobox-CcK1PxyF.js";import{g as E}from"./getInputValidation-CUi6Oel7.js";import{P as l}from"./project-eQY1xQe-.js";import{d as F}from"./index-DIGQ-MZU.js";import{u as H,r as _}from"./useProjectOptions-C17r5Psb.js";import{u as z}from"./vendor-router-D1GqFWiT.js";import"./vendor-redux-CJZrIb6x.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./input-group-Z3Qmt3PL.js";import"./textarea-Co48BFy3.js";import"./vendor-recharts-DmJlpLaF.js";import"./index-DQr7YlUK.js";const G=S().shape({project:q().label("Project").required(),role:M().oneOf(Object.keys(l)).label("Role").required(),cloudRole:T().label("Cloud Role").required()}),U=_.map(r=>({value:r.value,label:r.label})),J=()=>{const r=z(),[t,{isLoading:u}]=F(),{data:f=[],isLoading:j}=H(),h=f.map(o=>({value:o.value,label:o.label})),x={project:"",role:l.DATA_SCIENTIST,cloudRole:"",defaultRole:!1},{formState:{errors:g},register:C,handleSubmit:R,watch:b,setValue:s,reset:i}=B({defaultValues:x,resolver:A(G),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[v,N]=b(["role","project"]),X=p.useCallback(o=>{t({projectId:o.project,projectRole:o.role,cloudRole:o.cloudRole}).unwrap().then(c=>{i({project:"",role:l.ALL,cloudRole:"",defaultRole:!1}),d.success(`New mapping created: ${o.project} -> ${o.cloudRole}`)}).catch(c=>{const w=c.response.data.errorMsg;d.error(w)})},[t,i]);return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"mb-5 flex gap-5",children:[e.jsxs("div",{className:"flex w-[180px] flex-col gap-2",children:[e.jsx(a,{children:"Project"}),e.jsx(m,{options:h,value:N,onChange:o=>{o&&s("project",o,{shouldValidate:!0,shouldDirty:!0})},placeholder:"pick a project",disabled:j})]}),e.jsxs("div",{className:"flex w-[180px] flex-col gap-2",children:[e.jsx(a,{children:"Role"}),e.jsx(m,{options:U,value:v,onChange:o=>{o&&s("role",o,{shouldValidate:!0,shouldDirty:!0})},placeholder:"pick a role"})]})]}),e.jsxs("div",{className:"mb-5 flex flex-col gap-2",children:[e.jsx(a,{children:"Cloud Role"}),e.jsx(D,{...C("cloudRole"),placeholder:"arn:aws:iam::XXXXXXXXXX:roles/s3-role",...E("cloudRole",g)})]}),e.jsxs("div",{className:"flex justify-end gap-5",children:[e.jsx(n,{type:"button",variant:"secondary",onClick:()=>r(P(V.settings.iamRoleChaining.list)),children:"Back"}),e.jsx(n,{type:"button",loading:u,onClick:R(X),children:"Create new role chaining"})]})]})},K=p.memo(J),be=()=>($(I.iamRole),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(y,{children:[e.jsx(k,{children:e.jsx(L,{children:"Create new role chaining"})}),e.jsx(O,{children:e.jsx(K,{})})]})}));export{be as default};
