import{r}from"./vendor-react-CTtPmzVP.js";import{j as o,a6 as B,am as D,ak as w,cu as L,at as H,W as x}from"./vendor-mui-core-CKKG_1TN.js";import{b9 as S,F as T,b3 as Y,b2 as z}from"./vendor-ux-DjXlxcvL.js";import{Z as M,Q as N,G as P,f as E,bl as W}from"./index-BEfIUbZC.js";import{n as A}from"./vendor-utils-CUs2ebe7.js";import{b as F}from"./team-DkV63Yjl.js";import{C as G}from"./confirm-D6AvlbAp.js";import{P as K}from"./permission-CeqEAPPT.js";import{C as Q}from"./click-to-copy-Dk6ZAJOw.js";function Z({invitations:a=[],onRefresh:v=A}){const{api:C,inService:d}=M(),{t,locale:y}=r.useContext(S),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=F(),[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 E(800)}catch(n){console.error(n)}finally{c(!1),m(null)}}},k=()=>{c(!1),m(null)},p=e=>l?W({inviteId:e.inviteId,endpoint:l}):"",R=[{label:t("team.inviting.link"),name:"inviteId",options:{sort:!1,customBodyRenderLite:e=>{const n=s[e];return l?o.jsx(Q,{children:p(n)}):o.jsx(B,{size:16})}}},{label:t("common.role"),name:"role",widtn:70,options:{sort:!1,customBodyRender:e=>{const n=j.find(u=>u.name===e);return n?.title?o.jsx(D,{title:e,children:n.title}):e||"--"}}},{label:t("common.remark"),name:"remark",options:{sort:!1,customBodyRender:e=>e||"--"}},{label:t("team.inviting.inviter"),name:"inviter.fullName",options:{sort:!1,customBodyRender:(e,{rowIndex:n})=>s[n]?.inviter?.fullName}},{label:t("common.expires"),name:"expireDate",options:{sort:!1,customBodyRender:e=>o.jsx(w,{children:N(e).format("YYYY-MM-DD HH:mm")})}},{label:t("common.actions"),name:"",width:100,align:"center",options:{sort:!1,customBodyRenderLite:e=>{const n=s[e];return o.jsx(K,{permission:d?"":"mutate_team",role:d?P:[],children:o.jsxs(T,{onClick:()=>m({title:t("team.inviting.delete.title"),description:t("team.inviting.delete.description",{link:p(n)}),confirm:t("common.delConfirm"),cancel:t("common.cancel"),onConfirm:()=>I(n),onCancel:k}),size:"small",color:"error",variant:"text",children:[o.jsx(L,{style:{fontSize:"1.2em"}}),t("common.delete")]})})}}}];return o.jsxs(_,{children:[s.length?o.jsx(Y,{locale:y,data:[...s],columns:R,verticalKeyWidth:100,options:{download:!1,filter:!1,print:!1,search:!1,viewColumns:!1}}):o.jsx(z,{sx:{minHeight:200},children:t("common.empty")}),i&&o.jsx(G,{title:i.title,description:i.description,confirm:i.confirm,cancel:i.cancel,params:i.params,onConfirm:i.onConfirm,onCancel:i.onCancel})]})}Z.propTypes={invitations:x.array,onRefresh:x.func};const _=H.div`
  margin-top: -20px;
`;export{Z as I};
