import vue from 'vue'
import loadingComponent from './loading.vue'

const LoadingConstructor = vue.extend(loadingComponent)

let LoadingDom

function showLoading() {
  if(!LoadingDom) {
    LoadingDom = new LoadingConstructor({
      el: document.createElement('div'),
      data() {
        return {
          show:true
        }
      },
    })
    document.body.appendChild(LoadingDom.$el)

  } else {
    LoadingDom.show = true
  }
}

function hideLoading() {
  if(LoadingDom) {
    LoadingDom.show = false
  }
}

function registryLoading() {
  vue.prototype.$showLoading = showLoading
  vue.prototype.$hideLoading = hideLoading
}

export default registryLoading