import{ad as I,P as C,D as P,g as y,r as u,aa as M}from"./index-CU1_ljpG.js";const p=Symbol("userRecruitment");function R(){const n=C(),S=P(),i=u([]),o=u([]),v=u(!1),d=u(null),a=u(null),s=u(null),g=y(()=>i.value.length),w=y(()=>i.value.length+o.value.length);async function c(){v.value=!0,d.value=null;try{const e=n.allServerDomains(),[r,F]=await Promise.all([Promise.allSettled(e.map(async t=>{const l=await n.clientForServer(t).getMyRecruitmentInvites();return{domain:t,invites:l.invites}})),Promise.allSettled(e.map(async t=>{const l=await n.clientForServer(t).getMyRecruitmentRequests();return{domain:t,requests:l.requests}}))]),f=[];for(const t of r)if(t.status==="fulfilled")for(const l of t.value.invites)f.push({...l,sourceServer:t.value.domain});const m=[];for(const t of F)if(t.status==="fulfilled")for(const l of t.value.requests)m.push({...l,sourceServer:t.value.domain});i.value=f,o.value=m}catch(e){d.value=e instanceof Error?e.message:"Failed to load invitations",i.value=[],o.value=[]}finally{v.value=!1}}async function h(e){s.value=e.id,a.value=null;try{await n.clientForServer(e.sourceServer).updateMyRecruitmentInvite(e.id,{state:"ACCEPTED"}),await S.loadCommunities(),await c()}catch(r){a.value=r instanceof Error?r.message:"Failed to accept invitation"}finally{s.value=null}}async function E(e){s.value=e.id,a.value=null;try{await n.clientForServer(e.sourceServer).updateMyRecruitmentInvite(e.id,{state:"REJECTED"}),await c()}catch(r){a.value=r instanceof Error?r.message:"Failed to reject invitation"}finally{s.value=null}}async function q(e){s.value=e.id,a.value=null;try{await n.clientForServer(e.sourceServer).deleteMyRecruitmentRequest(e.id),await c()}catch(r){a.value=r instanceof Error?r.message:"Failed to withdraw request"}finally{s.value=null}}return{invites:i,requests:o,loading:v,error:d,actionError:a,actionInProgressId:s,pendingInviteCount:g,pendingCount:w,load:c,acceptInvite:h,rejectInvite:E,withdrawRequest:q}}function D(){const n=R();return M(p,n),n}function U(){const n=I(p,null);return n||R()}export{D as p,U as u};
//# sourceMappingURL=useUserRecruitment-CrLCOi1l.js.map
