import Invite from './index.vue'

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

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

    store.commit('setPopInviteType', type)

    instance = new Constructor({
      el: document.createElement('div'),
      computed: {
        $store () { return store }
      },
      data () {
        return {
          visible: true
        }
      }
    })

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

export default Invite
