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 Y,W as x}from"./vendor-mui-core-DnR6WYuU.js";import{b2 as H,J as S,aZ as T,aY as z}from"./vendor-ux-DMZIE6wA.js";import{Z as M,Q as N,G as P,e as E,bq as W}from"./index-DwyzCfdd.js";import{n as Z}from"./vendor-utils-D5UG1a5Y.js";import{b as q}from"./team-BWkxYdcc.js";import{C as A}from"./confirm-Bpit6U3-.js";import{P as G}from"./permission-C0bmOzVj.js";import{C as J}from"./click-to-copy-CwdgHxjB.js";function K({invitations:a=[],onRefresh:v=Z}){const{api:C,inService:d}=M(),{t,locale:y}=r.useContext(H),{teamDid:h,invitations:f,refresh:g,endpoint:l,roles:j}=q(),[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(J,{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(G,{permission:d?"":"mutate_team",role:d?P:[],children:o.jsxs(S,{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(Q,{children:[s.length?o.jsx(T,{locale:y,data:[...s],columns:b,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(A,{title:i.title,description:i.description,confirm:i.confirm,cancel:i.cancel,params:i.params,onConfirm:i.onConfirm,onCancel:i.onCancel})]})}K.propTypes={invitations:x.array,onRefresh:x.func};const Q=Y.div`
  margin-top: -20px;
`;export{K as I};
