import{u as M,f8 as A,cH as P,r as a,fA as b,v as S,w as O,x as m,dX as $,fB as N,fC as Q,j as e,bc as s,f as p,af as q,Z as u,a as R,V as h,bf as C,aG as G,O as _}from"./index-d6499a22.js";import{N as B}from"./NoData-789df290.js";import{g as U,r as V}from"./iamRoleUtils-0d5d3309.js";const K=()=>{var l;const{id:t}=M(),o=A(+t,{skip:!t}),{data:{email:n}={}}=P();return{isDataOwner:a.useMemo(()=>{var c;const i=(c=o.currentData)==null?void 0:c.projectTeam.find(j=>j.projectTeamPK.teamMember===n);return(i==null?void 0:i.teamRole)===b.DATA_OWNER},[n,(l=o.currentData)==null?void 0:l.projectTeam])}},W=S.injectEndpoints({endpoints:t=>({getRoleChainingList:t.query({query:({id:o})=>({url:`/project/${o}/cloud/role-mappings?sort_by=ID`}),providesTags:O.providesList(m.IAMRoleChainingTags.RoleChainingList),transformResponse:o=>o.count>0?o.items:[]}),updateRoleChainingDefault:t.mutation({query:({projectId:o,id:n,defaultRole:r})=>{const l=$.stringify({defaultRole:r});return{url:`/project/${o}/cloud/role-mappings/${n}?${l}`,method:"put"}},invalidatesTags:(o,n)=>[{type:m.IAMRoleChainingTags.RoleChainingAdminList},{type:m.IAMRoleChainingTags.RoleChainingList}]})})}),{useGetRoleChainingListQuery:ee,useUpdateRoleChainingDefaultMutation:Z}=W,z=({roleChaining:t,isEditable:o,projectOptions:n,projectLoading:r})=>{const[l,i]=a.useState(!1),[c,{isLoading:j}]=N(),[f,{isLoading:y}]=Q(),[E,{isLoading:w}]=Z(),[T,D]=a.useState(t.projectId),[x,k]=a.useState(U(t.projectRole)),[g,L]=a.useState(t.cloudRole);K();const v=a.useCallback(()=>{f({id:t.id})},[f,t.id]),I=a.useCallback(async()=>{await c({id:t.id,data:{projectRole:x,cloudRole:g}}),i(!1)},[g,x,t.id,c]);return!o||!l?e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(p,{width:"6px",children:t.id})}),o&&e.jsx(s.Cell,{children:e.jsx(p,{width:"85px",overflow:"hidden",children:t.projectName})}),e.jsx(s.Cell,{children:e.jsx(p,{width:"85px",children:t.projectRole})}),e.jsx(s.Cell,{children:e.jsx(p,{width:o?"245px":"300px",overflow:"hidden",children:t.cloudRole})}),!o&&e.jsx(s.Cell,{children:w&&e.jsx(q,{color:"labels.green",icon:u.validate,size:"lg"})}),o&&e.jsx(s.Cell,{pl:"0px",children:e.jsxs(R,{flexDirection:"row",children:[e.jsx(h,{icon:u.bin,intent:"ghost",tooltip:"delete",disabled:y,onClick:v}),e.jsx(h,{icon:u.edit,intent:"ghost",tooltip:"edit",onClick:()=>{i(!0)}})]})})]}):e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(p,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(C,{width:"85px",value:T,options:n||[],placeholder:"pick a project",height:"fit-content",appendToBody:!0,disabled:r,onChange:d=>{D(d.key)}})}),e.jsx(s.Cell,{children:e.jsx(C,{width:"85px",value:x,options:V,placeholder:"pick a role",height:"fit-content",appendToBody:!0,onChange:d=>{k(d.key)}})}),e.jsx(s.Cell,{children:e.jsx(G,{width:"245",defaultValue:g,onChange:d=>L(d.target.value)})}),e.jsx(s.Cell,{pl:"0px",children:e.jsxs(R,{flexDirection:"row",children:[e.jsx(h,{intent:"ghost",icon:u.cross,tooltip:"cancel",disabled:j,onClick:()=>{i(!1)}}),e.jsx(h,{intent:"ghost",icon:u.validate,tooltip:"save",disabled:j,onClick:I})]})})]})},H=a.memo(z),X=({roleChaining:t,isEditable:o,projectOptions:n,projectLoading:r})=>{const l=o?["id","project name","project role","cloud role",""]:["id","project role","cloud role",""];return e.jsx(R,{mt:"28px",sx:{th:{fontWeight:"700"}},children:t.length>0?e.jsx(s,{legend:l,middleColumn:o?3:2,children:t.map(i=>e.jsx(H,{roleChaining:i,isEditable:o,projectOptions:n,projectLoading:r},i.id))}):e.jsx(_,{my:"40px",children:e.jsx(B,{mainText:"No result found"})})})},te=a.memo(X);export{te as R,ee as u};
