import Clipboard from 'clipboard'
export default function handleClipboard (text, event, fn) {
  const clipboard = new Clipboard(event.target, {
    text: () => text
  })
  clipboard.on('success', () => {
    if (typeof fn === 'function') {
      fn('success')
    }
    clipboard.off('error')
    clipboard.off('success')
    clipboard.destroy()
  })
  clipboard.on('error', () => {
    if (typeof fn === 'function') {
      fn('error')
    }
    clipboard.off('error')
    clipboard.off('success')
    clipboard.destroy()
  })
  clipboard.onClick(event)
}
