import SnakeBar from './SnakeBar.vue'
import Vue from 'vue'
let SnakeBarConstructor = Vue.extend(SnakeBar)
let instance
let seed = 1
let index = 2000
let eleList = []
const install = () => {
  Object.defineProperty(Vue.prototype, '$snakebar', {
    get () {
      let id = 'snakebar_' + seed++
      const alertMsg = options => {
        instance = new SnakeBarConstructor({
          propsData: {msg:options}
        })
        index++
        instance.id = id
        instance.vm = instance.$mount()
        document.body.appendChild(instance.vm.$el)
        eleList.push(instance.vm.$el)
        setTimeout(()=> {
          document.body.removeChild(eleList.shift())
        },3000)
        instance.vm.$el.style.zIndex = index
        return instance.vm
      }
      return alertMsg
    }
  })
}
export default install