import{r}from"./vendor-react-DX7tU9aY.js";import{j as o,a7 as B,an as D,al as w,cs as H,aT as L,X as x}from"./vendor-mui-core-CDEc-eG6.js";import{b4 as T,b5 as M,aH as S,aG as Y}from"./vendor-ux-bFYdDLNG.js";import{X as z,M as E,E as N,e as P,bb as X}from"./index-DGZk149v.js";import{n as A}from"./vendor-utils-_C9URqjS.js";import{b as G}from"./team-CFKf1k_T.js";import{C as K}from"./confirm-o5NpDvNJ.js";import{P as W}from"./permission-CHcv6SG1.js";import{C as _}from"./click-to-copy-CH2KjgKM.js";function q({invitations:a=[],onRefresh:v=A}){const{api:C,inService:d}=z(),{t:n,locale:y}=r.useContext(T),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=G(),[i,m]=r.useState(null),[b,c]=r.useState(!1),s=r.useMemo(()=>a.length>0?a:f,[a,f]),I=async({inviteId:e})=>{if(!b){c(!0);try{await C.deleteInvitation({input:{teamDid:h,inviteId:e}}),g(),v?.(),await P(800)}catch(t){console.error(t)}finally{c(!1),m(null)}}},R=()=>{c(!1),m(null)},p=e=>l?X({inviteId:e.inviteId,endpoint:l}):"",k=[{label:n("team.inviting.link"),name:"inviteId",options:{sort:!1,customBodyRenderLite:e=>{const t=s[e];return l?o.jsx(_,{children:p(t)}):o.jsx(B,{size:16})}}},{label:n("common.role"),name:"role",widtn:70,options:{sort:!1,customBodyRender:e=>{const t=j.find(u=>u.name===e);return t?.title?o.jsx(D,{title:e,children:t.title}):e||"--"}}},{label:n("common.remark"),name:"remark",options:{sort:!1,customBodyRender:e=>e||"--"}},{label:n("team.inviting.inviter"),name:"inviter.fullName",options:{sort:!1,customBodyRender:(e,{rowIndex:t})=>s[t]?.inviter?.fullName}},{label:n("common.expires"),name:"expireDate",options:{sort:!1,customBodyRender:e=>o.jsx(w,{children:E(e).format("YYYY-MM-DD HH:mm")})}},{label:n("common.actions"),name:"",width:100,align:"center",options:{sort:!1,customBodyRenderLite:e=>{const t=s[e];return o.jsx(W,{permission:d?"":"mutate_team",role:d?N:[],children:o.jsxs(M,{onClick:()=>m({title:n("team.inviting.delete.title"),description:n("team.inviting.delete.description",{link:p(t)}),confirm:n("common.delConfirm"),cancel:n("common.cancel"),onConfirm:()=>I(t),onCancel:R}),size:"small",color:"error",variant:"text",children:[o.jsx(H,{style:{fontSize:"1.2em"}}),n("common.delete")]})})}}}];return o.jsxs(F,{children:[s.length?o.jsx(S,{locale:y,data:[...s],columns:k,verticalKeyWidth:100,options:{download:!1,filter:!1,print:!1,search:!1,viewColumns:!1}}):o.jsx(Y,{sx:{minHeight:200},children:n("common.empty")}),i&&o.jsx(K,{title:i.title,description:i.description,confirm:i.confirm,cancel:i.cancel,params:i.params,onConfirm:i.onConfirm,onCancel:i.onCancel})]})}q.propTypes={invitations:x.array,onRefresh:x.func};const F=L.div`
  margin-top: -20px;
`;export{q as I};
