import{r as s,ff as L,fg as S,j as e,b_ as o,f as i,$ as h,i as d,C as c,bd as C,b2 as $,L as M,bS as P}from"./index-46ma1THH.js";import{u as y,g as N,r as O}from"./useProjectOptions-Cg26SvBL.js";const T=({roleChaining:t,isEditable:l})=>{const{data:a=[],isLoading:n}=y(),[R,r]=s.useState(!1),[u,{isLoading:m}]=L(),[f,{isLoading:g}]=S(),[w,b]=s.useState(t.projectId),[j,k]=s.useState(N(t.projectRole)),[x,v]=s.useState(t.cloudRole),D=s.useCallback(()=>{f({id:t.id})},[f,t.id]),I=s.useCallback(async()=>{await u({id:t.id,data:{projectRole:j,cloudRole:x}}),r(!1)},[x,j,t.id,u]);return!l||!R?e.jsxs(o.Row,{children:[e.jsx(o.Cell,{children:e.jsx(i,{width:"6px",children:t.id})}),l&&e.jsx(o.Cell,{children:e.jsx(i,{width:"85px",overflow:"hidden",children:t.projectName})}),e.jsx(o.Cell,{children:e.jsx(i,{width:"85px",children:t.projectRole})}),e.jsx(o.Cell,{children:e.jsx(i,{overflow:"hidden",children:t.cloudRole})}),l&&e.jsx(o.Cell,{pl:"0px",children:e.jsxs(h,{flexDirection:"row",children:[e.jsx(d,{icon:c.bin,intent:"ghost",tooltip:"delete",disabled:g,onClick:D}),e.jsx(d,{icon:c.edit,intent:"ghost",tooltip:"edit",onClick:()=>{r(!0)}})]})})]}):e.jsxs(o.Row,{children:[e.jsx(o.Cell,{children:e.jsx(i,{width:"6px",children:t.id})}),e.jsx(o.Cell,{children:e.jsx(C,{width:"max-content",value:`${w}`,options:a||[],placeholder:"pick a project",height:"fit-content",isDisabled:n,onChange:p=>b(+p)})}),e.jsx(o.Cell,{children:e.jsx(C,{width:"max-content",value:j,options:O,placeholder:"pick a role",onChange:k})}),e.jsx(o.Cell,{children:e.jsx($,{width:"245",defaultValue:x,onChange:p=>v(p.target.value)})}),e.jsx(o.Cell,{pl:"0px",children:e.jsxs(h,{flexDirection:"row",children:[e.jsx(d,{intent:"ghost",icon:c.cross,tooltip:"cancel",disabled:m,onClick:()=>{r(!1)}}),e.jsx(d,{intent:"ghost",icon:c.validate,tooltip:"save",disabled:m,onClick:I})]})})]})},U=s.memo(T),J=({roleChaining:t,isEditable:l})=>{const a=l?["id","project name","project role","cloud role",""]:["id","project role","cloud role",""];return e.jsx(h,{mt:"28px",sx:{th:{fontWeight:"700"}},children:t.length>0?e.jsx(o,{legend:a,middleColumn:l?3:2,children:t.map(n=>e.jsx(U,{roleChaining:n,isEditable:l},n.id))}):e.jsx(M,{my:"40px",children:e.jsx(P,{mainText:"No result found"})})})},W=s.memo(J);export{W as R};
