import{r as t,j as e}from"./vendor-react-wBh_31cN.js";import{b as u,e as a,T as L,a as y,c as P,d as S}from"./table-a0YeQrHM.js";import{N as z}from"./NoData-BtM2pAIA.js";import{I as n}from"./icon-button-BZeFL7T7.js";import{I as M}from"./input-DFI7JniT.js";import{C as R}from"./combobox-QqI9aNup.js";import{T as i}from"./tooltip-DFFgUYh6.js";import{C as $}from"./confirmation-dialog-C7dws5K4.js";import{b as B,c as H}from"./index-Cs_VUG1d.js";import{u as V,g as E,r as F}from"./useProjectOptions-DNIvu1Mu.js";import{ai as K,ah as U,Y as W,a6 as X}from"./vendor-icons-BUUmD6ht.js";const Y=({roleChaining:s,isEditable:l})=>{const{data:r=[],isLoading:c}=V(),[d,m]=t.useState(!1),[g,x]=t.useState(!1),[h,{isLoading:f}]=B(),[b,{isLoading:N}]=H(),[v,T]=t.useState(s.projectId),[p,C]=t.useState(E(s.projectRole)),[j,k]=t.useState(s.cloudRole),I=r.map(o=>({value:o.value,label:o.label})),w=F.map(o=>({value:o.value,label:o.label})),O=t.useCallback(async()=>{await b({id:s.id}),x(!1)},[b,s.id]),D=t.useCallback(async()=>{await h({id:s.id,data:{projectRole:p,cloudRole:j}}),m(!1)},[j,p,s.id,h]);return!l||!d?e.jsxs(u,{children:[e.jsx(a,{children:e.jsx("span",{className:"text-xs font-bold",children:s.id})}),l&&e.jsx(a,{children:e.jsx("span",{className:"max-w-[85px] truncate text-xs font-bold",children:s.projectName})}),e.jsx(a,{children:e.jsx("span",{className:"text-xs font-bold",children:s.projectRole})}),e.jsx(a,{children:e.jsx("span",{className:"truncate text-xs font-bold",children:s.cloudRole})}),l&&e.jsxs(a,{children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(i,{content:"delete",children:e.jsx(n,{disabled:N,onClick:()=>x(!0),children:e.jsx(K,{className:"size-4"})})}),e.jsx(i,{content:"edit",children:e.jsx(n,{onClick:()=>m(!0),children:e.jsx(U,{className:"size-4"})})})]}),e.jsx($,{open:g,onOpenChange:x,title:"Delete role mapping",description:e.jsxs(e.Fragment,{children:["Removes the cloud role mapping"," ",e.jsx("code",{className:"font-mono",children:s.cloudRole})," ","for project"," ",e.jsx("code",{className:"font-mono",children:s.projectName}),". Workloads relying on this mapping will lose cloud access."]}),confirmLabel:"Delete",confirmVariant:"destructive",isLoading:N,onConfirm:O})]})]}):e.jsxs(u,{children:[e.jsx(a,{children:e.jsx("span",{className:"text-xs font-bold",children:s.id})}),e.jsx(a,{children:e.jsx("div",{className:"w-[160px]",children:e.jsx(R,{options:I,value:`${v}`,onChange:o=>o&&T(+o),placeholder:"pick a project",disabled:c})})}),e.jsx(a,{children:e.jsx("div",{className:"w-[160px]",children:e.jsx(R,{options:w,value:p,onChange:o=>o&&C(o),placeholder:"pick a role"})})}),e.jsx(a,{children:e.jsx(M,{className:"w-[245px]",defaultValue:j,onChange:o=>k(o.target.value)})}),e.jsx(a,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(i,{content:"cancel",children:e.jsx(n,{disabled:f,onClick:()=>m(!1),children:e.jsx(W,{className:"size-4"})})}),e.jsx(i,{content:"save",children:e.jsx(n,{disabled:f,onClick:D,children:e.jsx(X,{className:"size-4"})})})]})})]})},q=t.memo(Y),A=({roleChaining:s,isEditable:l})=>{const r=l?["id","project name","project role","cloud role",""]:["id","project role","cloud role",""];return e.jsx("div",{className:"mt-7",children:s.length>0?e.jsxs(L,{children:[e.jsx(y,{children:e.jsx(u,{children:r.map((c,d)=>e.jsx(P,{children:c},d))})}),e.jsx(S,{children:s.map(c=>e.jsx(q,{roleChaining:c,isEditable:l},c.id))})]}):e.jsx("div",{className:"my-10",children:e.jsx(z,{mainText:"No result found"})})})},ce=t.memo(A);export{ce as R};
