import e from"@tencentcloud/chat";import t from"tim-upload-plugin";import n from"tim-profanity-filter-plugin";class i{constructor(){this.serviceMap=new Map}registerService(e,t){this.serviceMap.has(e)||(console.log(`TUIServiceManager.registerService serviceName:${e}`),this.serviceMap.set(e,t))}unregisterService(e){this.serviceMap.has(e)&&(console.log(`TUIServiceManager.unregisterService serviceName:${e}`),this.serviceMap.delete(e))}getService(e){return this.serviceMap.get(e)}callService(e){const{serviceName:t,method:n,params:i,callback:s}=e,r=this.getService(t);if(console.log(`TUIServiceManager.callService serviceName:${t}, service:`,r),r)return r.onCall(n,i,s)}}class s{constructor(){this.extensionMap=new Map}registerExtension(e,t){if(console.log(`TUIExtensionManager.registerExtension extensionID:${e}`),!this.extensionMap.has(e)){const t=[];this.extensionMap.set(e,t)}const n=this.extensionMap.get(e);-1===n.indexOf(t)&&n.push(t)}unregisterExtension(e,t){if(console.log(`TUIExtensionManager.unregisterExtension extensionID:${e}`),this.extensionMap.has(e)){const n=this.extensionMap.get(e),i=n.indexOf(t);i>-1&&n.splice(i,1)}}getExtensionList(e,t){console.log(`TUIExtensionManager.getExtensionList extensionID:${e}, params:${t?JSON.stringify(t):void 0}`);let n=[],i=[];if(this.extensionMap.has(e)){n=this.extensionMap.get(e);for(let s=0;s-1&&e.splice(t,1)}}notifyEvent(e,t,n){const i=this.getKey(e,t);if(console.log(`TUIEventManager.notifyEvent eventName:${e} subKey:${t} params:${JSON.stringify(n)}`),this.eventMap.has(i)){this.eventMap.get(i).forEach((i=>{i.onNotifyEvent(e,t,n)}))}}getKey(e,t){let n=e;return t&&(n=`${e}-${n}`),n}}class o{constructor(){this.serviceManager=new i,this.extensionManager=new s,this.eventManager=new r}static getInstance(){return o.instance||(console.log("TUICore.getInstance ok."),o.instance=new o),o.instance}registerService(e,t){return this.serviceManager.registerService(e,t)}unregisterService(e){return this.serviceManager.unregisterService(e)}getService(e){return this.serviceManager.getService(e)}callService(e){return this.serviceManager.callService(e)}registerExtension(e,t){return this.extensionManager.registerExtension(e,t)}unregisterExtension(e,t){return this.extensionManager.unregisterExtension(e,t)}getExtensionList(e,t){return this.extensionManager.getExtensionList(e,t)}registerEvent(e,t,n){return this.eventManager.registerEvent(e,t,n)}unregisterEvent(e,t,n){return this.eventManager.unregisterEvent(e,t,n)}notifyEvent(e,t,n){return this.eventManager.notifyEvent(e,t,n)}}const a=["vue2","vue3"],E={TUILogin:{EVENT:{LOGIN_STATE_CHANGED:"loginStateChanged"},EVENT_SUB_KEY:{USER_LOGIN_SUCCESS:"userLoginSuccess",USER_LOGOUT_SUCCESS:"userLogoutSuccess",USER_KICKED_OFFLINE:"userKickedOffline",USER_SIG_EXPIRED:"userSigExpired"}},TUIConversation:{SERVICE:{NAME:"TUIConversationService",METHOD:{CREATE_CONVERSATION:"createConversation",HIDE_CONVERSATION_HEADER:"hideConversationHeader"}},EXTENSION:{CONV_POP_MENU:{EXT_ID:"conversationPopMenu"},CONV_GROUP:{EXT_ID:"conversationGroup"}}},TUIChat:{SERVICE:{NAME:"TUIChatService",METHOD:{UPDATE_MESSAGE_LIST:"updateMessageList",SEND_CUSTOM_MESSAGE:"sendCustomMessage",SEND_TEXT_MESSAGE:"sendTextMessage",SET_CHAT_TYPE:"setChatType"}},EXTENSION:{INPUT_MORE:{EXT_ID:"inputToolBarMore"},MSG_POP_MENU:{EXT_ID:"messagePopMenu"},CHAT_HEADER:{EXT_ID:"chatHeader"}}},TUIGroup:{SERVICE:{NAME:"TUIGroupService",METHOD:{CREATE_GROUP:"createGroup",OPEN_GROUP_MANAGEMENT:"openGroupManagement",SELECT_GROUP_MEMBER:"selectGroupMember"}}},TUIContact:{SERVICE:{NAME:"TUIContactService",METHOD:{SELECT_FRIEND:"selectFriend"}},EXTENSION:{CONTACT_LIST:{EXT_ID:"contactList"}}},TUISearch:{SERVICE:{NAME:"TUISearchService",METHOD:{SEARCH_GROUP:"searchGroup",SEARCH_USER:"searchUser",SEARCH_FRIEND:"searchFriend",SEARCH_GROUP_MEMBER:"searchGroupMember"}},EXTENSION:{SEARCH_MORE:{EXT_ID:"searchMore"}}},TUICalling:{SERVICE:{NAME:"TUICallingService",METHOD:{START_CALL:"startCall"}}},TUICustomerServicePlugin:{SERVICE:{NAME:"TUICustomerServicePlugin",METHOD:{ACTIVE_CONVERSATION:"activeConversation",FILTER_MESSAGE:"filterMessage"}},EXTENSION:{}},TUITranslate:{EVENT:{LANGUAGE_CHANGED:"languageChanged"},EVENT_SUB_KEY:{CHANGE_SUCCESS:"changeSuccess"}}},g="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting),c="undefined"!=typeof uni&&"undefined"==typeof window,S=g||c,h="undefined"!=typeof uni,u=("undefined"!=typeof uni||"undefined"!=typeof window)&&!S;g?wx:h?uni:window;const T=u&&window&&window.navigator&&window.navigator.userAgent||"",l=/Android/i.test(T),I=/(?:Windows Phone)/.test(T),v=/(?:SymbianOS)/.test(T),_=/iPad/i.test(T)||/iPhone/i.test(T)||/iPod/i.test(T),p=l||I||v||_,M=u&&!p,N=c&&!g;class U{constructor(){this.loginStatusPromise=new Map,this.SDKAppID=0,this.userID="",this.userSig=""}static getInstance(){return U.instance||(U.instance=new U),U.instance}login(t){const{SDKAppID:n,userID:i,userSig:s,framework:r}=t;return this.chat=e.create(Object.assign(Object.assign({},t),{scene:this.getStatScene(r)})),this.EVENT=e.EVENT,this.TYPES=e.TYPES,this.SDKAppID=n,this.userID=i,this.userSig=s,this.onChatEvent(),this.registerPlugin(t),this.loginChat(t)}logout(){return this.chat.logout().then((e=>(o.getInstance().notifyEvent(E.TUILogin.EVENT.LOGIN_STATE_CHANGED,E.TUILogin.EVENT_SUB_KEY.USER_LOGOUT_SUCCESS),Promise.resolve(e))))}destroy(){return this.chat.destroy().then((e=>(o.getInstance().notifyEvent(E.TUILogin.EVENT.LOGIN_STATE_CHANGED,E.TUILogin.EVENT_SUB_KEY.USER_LOGOUT_SUCCESS),Promise.resolve(e))))}setLogLevel(e){return this.chat.setLogLevel(e)}getContext(){return{chat:this.chat,SDKAppID:this.SDKAppID,userID:this.userID,userSig:this.userSig}}loginChat(e){const{userID:t,userSig:n}=e;return new Promise(((e,i)=>{this.chat.login({userID:t,userSig:n}).then((t=>{t.data.repeatLogin&&this.chat.isReady()&&e(t),this.loginStatusPromise.set("login",{resolve:e,reject:i,imResponse:t})})).catch((e=>{i(e)}))}))}onChatEvent(){this.chat.on(this.EVENT.SDK_READY,this.onSDKReady,this),this.chat.on(this.EVENT.SDK_NOT_READY,this.onSDKNotReady,this),this.chat.on(this.EVENT.KICKED_OUT,this.onUserKicked,this)}onSDKReady(){if(this.loginStatusPromise.has("login")){const e=this.loginStatusPromise.get("login");e.resolve(e.imResponse),o.getInstance().notifyEvent(E.TUILogin.EVENT.LOGIN_STATE_CHANGED,E.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS)}this.loginStatusPromise.delete("login")}onSDKNotReady(){if(this.loginStatusPromise.has("login")){this.loginStatusPromise.get("login").reject(new Error("sdk not ready"))}this.loginStatusPromise.delete("login")}onUserKicked(e){e.data.type!==this.TYPES.KICKED_OUT_USERSIG_EXPIRED?o.getInstance().notifyEvent(E.TUILogin.EVENT.LOGIN_STATE_CHANGED,E.TUILogin.EVENT_SUB_KEY.USER_KICKED_OFFLINE):o.getInstance().notifyEvent(E.TUILogin.EVENT.LOGIN_STATE_CHANGED,E.TUILogin.EVENT_SUB_KEY.USER_SIG_EXPIRED)}registerPlugin(e){const{useUploadPlugin:i=!1,useProfanityFilterPlugin:s=!1,TUIOfflinePush:r,offlinePushConfig:o}=e;!0===i&&this.chat.registerPlugin({"tim-upload-plugin":t}),!0===s&&this.chat.registerPlugin({"tim-profanity-filter-plugin":n}),N&&r&&o&&this.chat.registerPlugin({"tim-offline-push-plugin":r,offlinePushConfig:o})}getStatScene(e){let t;return e&&a.indexOf(e)>-1&&(t=this.genStatScene(e)),t}genStatScene(e){let t="";return h?(M&&(t=`k-${e}-pc-uni`),p&&(t=`k-${e}-h5-uni`),N&&(t=`k-${e}-app-uni`),g&&(t=`k-${e}-mp-uni`),t):(M&&(t=`k-${e}-pc`),p&&(t=`k-${e}-h5`),t)}}console.log("TUICore.VERSION:2.0.2");const C=o.getInstance(),f=U.getInstance();export{E as TUIConstants,C as TUICore,f as TUILogin,C as default};