import Invite from './index.vue'
import i18n from '@/util/lang/lang'

Invite.install = function (Vue, store, router) {
  const Constructor = Vue.extend(Invite)
  let instance

  Vue.prototype.$showInvite = (type, ext) => {
    if (instance) {
      document.body.removeChild(instance.$el)
      instance = null
    }

    instance = new Constructor({
      el: document.createElement('div'),
      router,
      computed: {
        $store () { return store }
      },
      i18n,
      data () {
        return {
          inviteType: type, // 弹框邀请类型{1:建群,2:邀请好友进群,3:删除群好友,4:添加群管理,5:转让群主}
          ext // 额外数据
        }
      }
    })

    document.body.appendChild(instance.$el)
  }
}

export default Invite
