import{r}from"./vendor-react-DX7tU9aY.js";import{j as o,a7 as B,an as D,al as w,ct as L,aT as P,X as x}from"./vendor-mui-core-D7t4vMS5.js";import{b3 as T,b4 as H,aQ as M,aP as S}from"./vendor-ux-Dl3wVbv_.js";import{W as Y,M as z,F as N,f as E,aP as W}from"./index-Ca33rdd_.js";import{n as A}from"./vendor-utils-BzQg432x.js";import{b as F}from"./team-7-48iuwj.js";import{C as K}from"./confirm-DQYDHHdS.js";import{P as Q}from"./permission-DhyiLNfC.js";import{C as X}from"./click-to-copy-RBTqACSW.js";function _({invitations:a=[],onRefresh:v=A}){const{api:C,inService:d}=Y(),{t,locale:y}=r.useContext(T),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=F(),[i,m]=r.useState(null),[I,c]=r.useState(!1),s=r.useMemo(()=>a.length>0?a:f,[a,f]),R=async({inviteId:e})=>{if(!I){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)}}},b=()=>{c(!1),m(null)},p=e=>l?W({inviteId:e.inviteId,endpoint:l}):"",k=[{label:t("team.inviting.link"),name:"inviteId",options:{sort:!1,customBodyRenderLite:e=>{const n=s[e];return l?o.jsx(X,{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:z(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(Q,{permission:d?"":"mutate_team",role:d?N:[],children:o.jsxs(H,{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:()=>R(n),onCancel:b}),size:"small",color:"error",variant:"text",children:[o.jsx(L,{style:{fontSize:"1.2em"}}),t("common.delete")]})})}}}];return o.jsxs(q,{children:[s.length?o.jsx(M,{locale:y,data:[...s],columns:k,verticalKeyWidth:100,options:{download:!1,filter:!1,print:!1,search:!1,viewColumns:!1}}):o.jsx(S,{sx:{minHeight:200},children:t("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})]})}_.propTypes={invitations:x.array,onRefresh:x.func};const q=P.div`
  margin-top: -20px;
`;export{_ as I};
