import e from"@tencentcloud/lite-chat/basic";const t="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&("mac"===wx.getSystemInfoSync().platform||"windows"===wx.getSystemInfoSync().platform),n="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting)||t,s="undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting),i="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),o="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),E="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),r="undefined"!=typeof jd&&"function"==typeof jd.getSystemInfoSync,a="undefined"!=typeof uni&&"undefined"==typeof window,S=n||s||i||o||E||r||a,c="undefined"!=typeof uni,g=("undefined"!=typeof uni||"undefined"!=typeof window)&&!S,T=s?qq:i?tt:o?swan:E?my:n?wx:a?uni:r?jd:g?window:{};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:s,callback:i}=e,o=this.getService(t);if(console.log(`TUIServiceManager.callService serviceName:${t}, service:`,o),o)return o.onCall(n,s,i)}}class h{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),s=n.indexOf(t);s>-1&&n.splice(s,1)}}getExtensionList(e,t){const n=t?`params:${JSON.stringify(t)}`:"";console.log(`TUIExtensionManager.getExtensionList extensionID:${e} ${n}`);let s=[],i=[];if(this.extensionMap.has(e)){s=this.extensionMap.get(e);for(let n=0;n(this.userID="",this.userSig="",this.TUICore.notifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.TUILogin.EVENT_SUB_KEY.USER_LOGOUT_SUCCESS),Promise.resolve(e)))}destroy(){return this.chat.destroy().then(e=>(this.userID="",this.userSig="",this.TUICore.notifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.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}}reportPlugin(){var e;for(const t in C)this.TUICore.getService(t)&&(null===(e=this.chat.callExperimentalAPI("isFeatureEnabledForStat",C[t]))||void 0===e||e.catch(()=>{}))}loginChat(e){const{userID:t,userSig:n}=e;return new Promise((e,s)=>{this.chat.login({userID:t,userSig:n}).then(t=>{t.data.repeatLogin&&this.chat.isReady()&&e(t),this.reportPlugin(),this.loginStatusPromise.set("login",{resolve:e,reject:s,imResponse:t})}).catch(e=>{s(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),this.isOnChatEvent=!0}offChatEvent(){this.isOnChatEvent&&(this.chat.off(this.EVENT.SDK_READY,this.onSDKReady,this),this.chat.off(this.EVENT.SDK_NOT_READY,this.onSDKNotReady,this),this.chat.off(this.EVENT.KICKED_OUT,this.onUserKicked,this),this.isOnChatEvent=!1)}onSDKReady(){if(this.loginStatusPromise.has("login")){this.TUICore.notifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS);const e=setTimeout(()=>{const t=this.loginStatusPromise.get("login");t.resolve(t.imResponse),clearTimeout(e),this.loginStatusPromise.delete("login")},500)}}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?this.TUICore.notifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.TUILogin.EVENT_SUB_KEY.USER_KICKED_OFFLINE):this.TUICore.notifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.TUILogin.EVENT_SUB_KEY.USER_SIG_EXPIRED)}_addSDKExtensions(){Array.isArray(T.__$RTC_CHAT__)&&T.__$RTC_CHAT__.length>0&&this.chat.use(T.__$RTC_CHAT__)}getStatScene(e){return e&&u.indexOf(e)>-1?"rn"===e?"38":c?"vue2"===e?"31":"32":"vue2"===e?"29":"30":e}}class U{constructor(){this.eventMap=new Map}registerEvent(e,t,n){const s=this.getKey(e,t);if(console.log(`TUIEventManager.registerEvent eventName:${e} subKey:${t}`),!this.eventMap.has(s)){const e=[];this.eventMap.set(s,e)}const i=this.eventMap.get(s);-1===i.indexOf(n)&&(i.push(n),this.renotify(e,t,n))}unregisterEvent(e,t,n){console.log(`TUIEventManager.unregisterEvent eventName:${e} subKey:${t}`);const s=this.getKey(e,t);if(this.eventMap.has(s)){const e=this.eventMap.get(s),t=e.indexOf(n);t>-1&&e.splice(t,1)}}notifyEvent(e,t,n){const s=this.getKey(e,t),i=n?`params:${JSON.stringify(n)}`:"";if(console.log(`TUIEventManager.notifyEvent eventName:${e} subKey:${t} ${i}`),this.eventMap.has(s)){this.eventMap.get(s).forEach(s=>{s.onNotifyEvent(e,t,n)})}}getKey(e,t){let n=e;return t&&(n=`${e}-${n}`),n}renotify(e,t,n){if(e===_.TUILogin.EVENT.LOGIN_STATE_CHANGED&&t===_.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS){const{chat:e}=l.getInstance().getContext();e&&e.isReady()&&(n.onNotifyEvent(_.TUILogin.EVENT.LOGIN_STATE_CHANGED,_.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS),console.log("TUIEventManager.renotify success."))}}}class M{constructor(){this.serviceManager=new I,this.extensionManager=new h,this.eventManager=new U}static getInstance(){return T.__$RTC_TUICore__&&T.__$RTC_TUILogin__?T.__$RTC_TUICore__:(M.instance||(console.log("TUICore.getInstance ok."),M.instance=new M),T.__$RTC_TUICore__=M.instance,M.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)}}console.log("TUICore-Lite.VERSION:1.0.0");const N=M.getInstance(),v=l.getInstance(N);export{_ as TUIConstants,N as TUICore,v as TUILogin,N as default};