import{u as M,fc as A,cK as P,r as a,fG as b,p as S,q as Q,s as m,d$ as $,fH as q,fI as N,j as e,bd as s,g as p,ag as G,z as u,Q as R,A as h,bg as C,aH as O,o as _}from"./index-ea7817a2.js";import{N as z}from"./NoData-8733f606.js";import{g as K,r as U}from"./iamRoleUtils-7a0b61f9.js";const B=()=>{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])}},H=S.injectEndpoints({endpoints:t=>({getRoleChainingList:t.query({query:({id:o})=>({url:`/project/${o}/cloud/role-mappings?sort_by=ID`}),providesTags:Q.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:V}=H,W=({roleChaining:t,isEditable:o,projectOptions:n,projectLoading:r})=>{const[l,i]=a.useState(!1),[c,{isLoading:j}]=q(),[f,{isLoading:y}]=N(),[J,{isLoading:w}]=V(),[T,D]=a.useState(t.projectId),[x,k]=a.useState(K(t.projectRole)),[g,I]=a.useState(t.cloudRole);B();const v=a.useCallback(()=>{f({id:t.id})},[f,t.id]),L=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(G,{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:U,placeholder:"pick a role",height:"fit-content",appendToBody:!0,onChange:d=>{k(d.key)}})}),e.jsx(s.Cell,{children:e.jsx(O,{width:"245",defaultValue:g,onChange:d=>I(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:L})]})})]})},E=a.memo(W),F=({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(E,{roleChaining:i,isEditable:o,projectOptions:n,projectLoading:r},i.id))}):e.jsx(_,{my:"40px",children:e.jsx(z,{mainText:"No result found"})})})},te=a.memo(F);export{te as R,ee as u};
