import Vue from 'vue'
const intervalTime=1000
const preventReClick = Vue.directive('preventReClick', {
  inserted: function(el, binding) {
    preventReClickHandle(el, binding)
  }
  /* update(el, binding) {
    preventReClickHandle(el, binding)
  } */
})

export { preventReClick }

function preventReClickHandle(el, binding) {
  el.addEventListener('click', () => {
    if (!el.disabled) {
      if (el.tagName === 'BUTTON') {
        el.disabled = true
        setTimeout(() => {
          el.disabled = false
        }, binding.value || intervalTime)
      } else {
        el.style.pointerEvents="none"
        setTimeout(() => {
          el.style.pointerEvents="auto"
        }, binding.value || intervalTime)
      }
    }
  })
}
