import { useToast } from '../toast'

export const useCopyToClipboard = (copyText: string) => {
  const { showSuccess, showError } = useToast()
  const isCopyDisabled = !window?.navigator?.clipboard?.writeText
  const copy = () => {
    if (!isCopyDisabled) {
      window?.navigator?.clipboard
        .writeText?.(copyText)
        .then(() => showSuccess(`Copied to clipboard: ${copyText}`))
        .catch(() => showError('Copy failed'))
    }
  }
  return { copy, isCopyDisabled }
}
