import { copyToClipboard, useQuasar } from 'quasar'
import { useI18n } from 'vue-i18n'

export function useCopyToClipboard () {
  const $q = useQuasar()
  const { t } = useI18n()

  const copy = async (text: string) => {
    try {
      await copyToClipboard(text)
      $q.notify({
        message: t('copy') || 'Copied',
        classes: 'bg-grey-8 text-white',
        timeout: 1500
      })
      return true
    } catch {
      return false
    }
  }

  return { copy }
}
