import{u as I}from"./vue-i18n-90d534a9.js";import{l as L,I as s,q as g}from"./index-ae60edf9.js";import{C as t}from"./open-im-sdk-wasm-f19f04ec.js";import{l as D,j as G,x as C,w as O}from"./@vue-cb50a1c4.js";const f=L();function w(i,p=!1){const{t:m}=I(),e=D({offset:0,searchOffset:0,count:20,loading:!1,hasMore:!0,groupMemberList:[],searchMemberList:[]}),M=r=>{e.loading=!0,s.searchGroupMembers({groupID:i??f.storeCurrentGroupInfo.groupID,offset:e.searchOffset,count:20,keywordList:[r],isSearchMemberNickname:!0,isSearchUserID:!1}).then(({data:o})=>{e.searchMemberList=[...e.searchMemberList,...o],e.hasMore=o.length===e.count,e.searchOffset+=20,console.log(e.searchMemberList)}).catch(o=>g({message:m("getMemberFailed"),error:o})).finally(()=>e.loading=!1)},a=()=>{e.loading=!0,s.getGroupMemberList({groupID:i??f.storeCurrentGroupInfo.groupID,offset:e.offset,count:20,filter:0}).then(({data:r})=>{e.groupMemberList=[...e.groupMemberList,...r],e.hasMore=r.length===e.count,e.offset+=20,console.log(e.groupMemberList)}).catch(r=>g({message:m("getMemberFailed"),error:r})).finally(()=>e.loading=!1)},c=({data:r})=>{var n;const o=r;if(o.groupID===((n=e.groupMemberList[0])==null?void 0:n.groupID)){const d=e.groupMemberList.findIndex(h=>h.userID===o.userID);e.groupMemberList[d]={...o}}},u=({data:r})=>{var n;if(!p)return;r.groupID===((n=e.groupMemberList[0])==null?void 0:n.groupID)&&(e.offset=0,e.groupMemberList=[],a())},b=()=>{s.on(t.OnGroupMemberInfoChanged,c),s.on(t.OnGroupMemberAdded,u),s.on(t.OnGroupMemberDeleted,u)},l=()=>{s.off(t.OnGroupMemberInfoChanged,c),s.off(t.OnGroupMemberAdded,u),s.off(t.OnGroupMemberDeleted,u)};return G(()=>{b()}),C(()=>{l()}),O(()=>f.storeCurrentGroupInfo.groupID,r=>{r&&(e.groupMemberList=[],e.offset=0,e.loading=!1,e.hasMore=!0,a())},{immediate:!0}),{fetchState:e,getMemberData:a,searchMember:M}}export{w as u};
