import{r}from"./vendor-react-DX7tU9aY.js";import{j as o,a7 as B,an as D,al as w,cs as L,aT as T,X as x}from"./vendor-mui-core-CDEc-eG6.js";import{bj as H,bk as M,b3 as S,b2 as Y}from"./vendor-ux-PO0jFgJf.js";import{X as z,M as E,E as N,e as P,b1 as X}from"./index-CgSpL7jz.js";import{n as A}from"./vendor-utils-_C9URqjS.js";import{b as K}from"./team-Bso_Sjaa.js";import{C as W}from"./confirm-DhDNorbd.js";import{P as _}from"./permission-C2bdzuoM.js";import{C as q}from"./click-to-copy-BmatCVrP.js";function F({invitations:a=[],onRefresh:v=A}){const{api:C,inService:d}=z(),{t:n,locale:y}=r.useContext(H),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=K(),[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)}}},k=()=>{c(!1),m(null)},p=e=>l?X({inviteId:e.inviteId,endpoint:l}):"",R=[{label:n("team.inviting.link"),name:"inviteId",options:{sort:!1,customBodyRenderLite:e=>{const t=s[e];return l?o.jsx(q,{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(_,{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:k}),size:"small",color:"error",variant:"text",children:[o.jsx(L,{style:{fontSize:"1.2em"}}),n("common.delete")]})})}}}];return o.jsxs(G,{children:[s.length?o.jsx(S,{locale:y,data:[...s],columns:R,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(W,{title:i.title,description:i.description,confirm:i.confirm,cancel:i.cancel,params:i.params,onConfirm:i.onConfirm,onCancel:i.onCancel})]})}F.propTypes={invitations:x.array,onRefresh:x.func};const G=T.div`
  margin-top: -20px;
`;export{F as I};
