import { message } from 'antd'

// 点击复制
const copyWithTextarea = (text: string) => {
  const textArea = document.createElement('textarea')
  textArea.value = text
  textArea.style.position = 'fixed'
  textArea.style.left = '-9999px'
  textArea.style.top = '-9999px'
  document.body.appendChild(textArea)
  textArea.select()
  const copyTXT = document.execCommand('copy')
  document.body.removeChild(textArea)
  return copyTXT
}
export const handleCopyClick = (text: string) => {
  if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
    navigator.clipboard.writeText(text)
    message.success('链接已复制到剪贴板')
  } else {
    copyWithTextarea(text)
    message.success('链接已复制到剪贴板')
  }
}
