"use strict";const i=require("../common/vendor.js"),n=require("./utils/type-check.js"),t=require("./utils/env.js"),e=require("./plugins/extension-server/callkit.js");class s{constructor(){this.TUIComponents={},this.TUIPlugins={},this.TUICore=i.R,this.TUIChatEngine=i.qt,this.TUIGlobal=i.i,this.SDKAppID=0,this.TUIGlobal._isTIMCallKit=!0,i.R.registerEvent(i.E.TUILogin.EVENT.LOGIN_STATE_CHANGED,i.E.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS,this),i.R.registerEvent(i.E.TUITranslate.EVENT.LANGUAGE_CHANGED,i.E.TUITranslate.EVENT_SUB_KEY.CHANGE_SUCCESS,this),i.R.registerService(i.E.TUITranslatePlugin.SERVICE.NAME,1),i.R.registerService(i.E.TUIVoiceToTextPlugin.SERVICE.NAME,1)}onNotifyEvent(n,t,e){if(n===i.E.TUILogin.EVENT.LOGIN_STATE_CHANGED&&t===i.E.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS)this.login();if(n===i.E.TUITranslate.EVENT.LANGUAGE_CHANGED&&t===i.E.TUITranslate.EVENT_SUB_KEY.CHANGE_SUCCESS)(null==e?void 0:e.language)&&i.Wt.changeLanguage(e.language)}init(){s.isInitialized||(s.isInitialized=!0,t.isApp&&new e.CallkitPluginServer,i.i.TUIComponents=this.TUIComponents,i.i.TUIPlugins=this.TUIPlugins,console.warn("[TUIChatKit]: init success."))}login(){const{chat:n,SDKAppID:t,userID:e,userSig:s}=i.A.getContext();return this.SDKAppID=t,this.TUIChatEngine.login({chat:n,SDKAppID:t,userID:e,userSig:s}),this.chat=n,this.TUIChatEngine}component(n,t,e){var s,o;return(null==(s=null==this?void 0:this.TUIComponents)?void 0:s.componentName)?console.warn(`[TUIChatKit]: ${null==(o=null==this?void 0:this.TUIComponents)?void 0:o.componentName} component has already been applied to target TUIChatEngine.`):(this.TUIComponents[n]=t,null==e||e.component(n,t)),e&&!i.i.Vue&&(i.i.Vue=e),this.TUIChatEngine}components(i,t){var e;return i&&n.isObject(i)?null==(e=null==Object?void 0:Object.keys(i))||e.forEach((n=>{this.component(n,i[n],t)})):console.warn("[TUIChatKit]: components is empty or not object."),this.TUIChatEngine}use(i,t,e){if(this.TUICore)return this.TUIPlugins[i]?console.warn(`[TUIChatKit]: Plugin ${this.TUIPlugins[i]} has already been applied to target TUIChatEngine.`):t&&n.isFunction(null==t?void 0:t.plugin)?(this.TUIPlugins[i]=t,null==t||t.plugin(this,e)):n.isFunction(t)?(this.TUIPlugins[i]=t,t(this,e)):console.warn('[TUIChatKit]: A plugin must either be a function or an object with an "plugin" function.'+this.TUIPlugins[i]+"does not comply with the above rules."),this.TUIChatEngine;console.warn(`[TUIChatKit]: Plugin ${this.TUIPlugins[i]} can't be used before init.`)}}exports.TUIChatKit=s;
