/* eslint-disable space-before-function-paren */
// 导入XMPP入口组件
import XmppChatIndex from './src/chat/index'
import XmppChatFriendIndex from './src/chat/friendIndex'
import XmppChatChatRoom from './src/chat/chatRoom'
import XmppChatSetting from './src/chat/setting'
import XmppChatGroupData from './src/chat/groupData'
import XmppChatChatSelectPanel from './src/chat/chatSelectPanel'
import XmppChatConllectMessage from './src/chat/conllectMessage'
import XmppGroupManagementIndex from './src/groupManagement/index'
import XmppCommonHeadPortrait from './src/common/HeadPortrait'
import XmppChatTelephoneRoom from './src/chat/telephoneRoom'

// js导入
import imLogin from './src/mixins/login.js'
import constData from './src/utils/constData.js'
import initBasicDbs from './src/utils/initBasicDbs.js'
import xmppMessage from './src/utils/onXmppMessage.js'
import contactsOrg from './src/utils/handledb/contactsOrg.js'
import contactsUser from './src/utils/handledb/contactsUser.js'
import emoji from './src/utils/handledb/emoji.js'
import friend from './src/utils/handledb/friend.js'
import msg from './src/utils/handledb/msg.js'
import tableInfo from './src/utils/handledb/tableInfo.js'
import xmppStore from './src/store/xmppStore.js'
import other from './src/utils/handledb/other.js'
import userSetting from './src/utils/userSetting.js'
import xmpp from './src/plugins/xmpp.js'

// 以对象的结构保存组件，便于遍历
const components = {
    XmppChatIndex,
    XmppChatFriendIndex,
    XmppChatChatRoom,
    XmppChatSetting,
    XmppChatGroupData,
    XmppChatChatSelectPanel,
    XmppChatConllectMessage,
    XmppGroupManagementIndex,
    XmppCommonHeadPortrait,
    XmppChatTelephoneRoom
}

// 定义 install 方法
const install = function (Vue) {
    if (install.installed) return
    install.installed = true
    // 遍历并注册全局组件
    Object.keys(components).forEach((key) => {
        Vue.component(key, components[key])
    })
}

if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue)
    // xmpp方法注入
    window.Vue.prototype.xmppUtils = {
        imLogin,
        constData,
        initBasicDbs,
        xmppMessage,
        contactsOrg,
        contactsUser,
        emoji,
        friend,
        msg,
        tableInfo,
        xmppStore,
        other,
        userSetting,
        xmpp
    }
}

export default {
    // 导出的对象必须具备一个 install 方法
    install,
    // 组件列表
    ...components
}
