import{r as s,fi as L,fj as M,j as e,bX as o,Q as i,B as h,f as c,Z as d,bm as f,aM as N,e as P}from"./index-dP1W1_bd.js";import{N as S}from"./NoData-DLZ_8GEo.js";import{u as y,g as O,r as T}from"./useProjectOptions-FXFkYH64.js";const $=({roleChaining:t,isEditable:l})=>{const{data:a=[],isLoading:n}=y(),[g,r]=s.useState(!1),[u,{isLoading:m}]=L(),[R,{isLoading:C}]=M(),[w,b]=s.useState(t.projectId),[j,k]=s.useState(O(t.projectRole)),[p,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:j,cloudRole:p}}),r(!1)},[p,j,t.id,u]);return!l||!g?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(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(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:x=>b(+x)})}),e.jsx(o.Cell,{children:e.jsx(f,{width:"max-content",value:j,options:T,placeholder:"pick a role",onChange:k})}),e.jsx(o.Cell,{children:e.jsx(N,{width:"245",defaultValue:p,onChange:x=>v(x.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})]})})]})},B=s.memo($),K=({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"})})})},_=s.memo(K);export{_ as R};
