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 T,W as x}from"./vendor-mui-core-DnR6WYuU.js";import{aT as H,w as N,aO as S,aN as Y}from"./vendor-ux-KtPBvlG0.js";import{Z as z,Q as M,G as P,e as E,bq as W}from"./index-DGg3AL9l.js";import{n as q}from"./vendor-utils-BqKQizRf.js";import{b as A}from"./team-D2fBm-il.js";import{C as G}from"./confirm-Dul9DyCY.js";import{P as K}from"./permission-CjBTXkmT.js";import{C as O}from"./click-to-copy-03_3P1nz.js";function Q({invitations:a=[],onRefresh:v=q}){const{api:C,inService:d}=z(),{t,locale:y}=r.useContext(H),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=A(),[i,m]=r.useState(null),[I,c]=r.useState(!1),s=r.useMemo(()=>a.length>0?a:f,[a,f]),k=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)}}},R=()=>{c(!1),m(null)},p=e=>l?W({inviteId:e.inviteId,endpoint:l}):"",b=[{label:t("team.inviting.link"),name:"inviteId",options:{sort:!1,customBodyRenderLite:e=>{const n=s[e];return l?o.jsx(O,{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:M(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(N,{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:()=>k(n),onCancel:R}),size:"small",color:"error",variant:"text",children:[o.jsx(L,{style:{fontSize:"1.2em"}}),t("common.delete")]})})}}}];return o.jsxs(Z,{children:[s.length?o.jsx(S,{locale:y,data:[...s],columns:b,verticalKeyWidth:100,options:{download:!1,filter:!1,print:!1,search:!1,viewColumns:!1}}):o.jsx(Y,{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})]})}Q.propTypes={invitations:x.array,onRefresh:x.func};const Z=T.div`
  margin-top: -20px;
`;export{Q as I};
