import{r as s,fp as L,fq as M,j as e,cc as o,d as n,q as h,n as c,v as d,be as f,aH as P,F as S,c5 as $}from"./index-Cox3ZWL0.js";import{u as q,g as y,r as N}from"./useProjectOptions-BTBN3QRh.js";const O=({roleChaining:t,isEditable:l})=>{const{data:a=[],isLoading:i}=q(),[g,r]=s.useState(!1),[u,{isLoading:m}]=L(),[R,{isLoading:C}]=M(),[w,v]=s.useState(t.projectId),[j,b]=s.useState(y(t.projectRole)),[x,k]=s.useState(t.cloudRole),D=s.useCallback(()=>{R({id:t.id})},[R,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||!g?e.jsxs(o.Row,{children:[e.jsx(o.Cell,{children:e.jsx(n,{width:"6px",children:t.id})}),l&&e.jsx(o.Cell,{children:e.jsx(n,{width:"85px",overflow:"hidden",children:t.projectName})}),e.jsx(o.Cell,{children:e.jsx(n,{width:"85px",children:t.projectRole})}),e.jsx(o.Cell,{children:e.jsx(n,{overflow:"hidden",children:t.cloudRole})}),l&&e.jsx(o.Cell,{pl:"0px",children:e.jsxs(h,{flexDirection:"row",children:[e.jsx(c,{icon:d.bin,intent:"ghost",tooltip:"delete",disabled:C,onClick:D}),e.jsx(c,{icon:d.edit,intent:"ghost",tooltip:"edit",onClick:()=>{r(!0)}})]})})]}):e.jsxs(o.Row,{children:[e.jsx(o.Cell,{children:e.jsx(n,{width:"6px",children:t.id})}),e.jsx(o.Cell,{children:e.jsx(f,{width:"max-content",value:`${w}`,options:a||[],placeholder:"pick a project",height:"fit-content",isDisabled:i,onChange:p=>v(+p)})}),e.jsx(o.Cell,{children:e.jsx(f,{width:"max-content",value:j,options:N,placeholder:"pick a role",onChange:b})}),e.jsx(o.Cell,{children:e.jsx(P,{width:"245",defaultValue:x,onChange:p=>k(p.target.value)})}),e.jsx(o.Cell,{pl:"0px",children:e.jsxs(h,{flexDirection:"row",children:[e.jsx(c,{intent:"ghost",icon:d.cross,tooltip:"cancel",disabled:m,onClick:()=>{r(!1)}}),e.jsx(c,{intent:"ghost",icon:d.validate,tooltip:"save",disabled:m,onClick:I})]})})]})},T=s.memo(O),F=({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(i=>e.jsx(T,{roleChaining:i,isEditable:l},i.id))}):e.jsx(S,{my:"40px",children:e.jsx($,{mainText:"No result found"})})})},U=s.memo(F);export{U as R};
