import{r as s,f2 as L,f3 as M,j as e,b$ as o,b as i,B as h,e as d,C as c,be as f,b5 as N,d as P}from"./index-C1DmWO_C.js";import{N as S}from"./NoData-Y_e6mfNf.js";import{u as T,g as $,r as y}from"./useProjectOptions-BhlzfZPS.js";const O=({roleChaining:t,isEditable:l})=>{const{data:a=[],isLoading:n}=T(),[C,r]=s.useState(!1),[u,{isLoading:m}]=L(),[R,{isLoading:g}]=M(),[w,b]=s.useState(t.projectId),[x,k]=s.useState($(t.projectRole)),[j,v]=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:x,cloudRole:j}}),r(!1)},[j,x,t.id,u]);return!l||!C?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(f,{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(f,{width:"max-content",value:x,options:y,placeholder:"pick a role",onChange:k})}),e.jsx(o.Cell,{children:e.jsx(N,{width:"245",defaultValue:j,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})]})})]})},B=s.memo(O),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(B,{roleChaining:n,isEditable:l},n.id))}):e.jsx(P,{my:"40px",children:e.jsx(S,{mainText:"No result found"})})})},W=s.memo(J);export{W as R};
