import Validate from './validate.vue'
import i18n from '@/util/lang/lang'

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

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

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

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

export default Validate
