export function copyTextToClipboard(text: string) {
  if (window.isSecureContext) {
    // navigator.clipboard is only available in secure contexts
    return navigator.clipboard.writeText(text)
  } else {
    // fallback - this should only be run locally
    unsecureCopy(text)
    return Promise.resolve()
  }
}

function unsecureCopy(text: string) {
  const textArea = document.createElement('textarea')
  textArea.value = text
  textArea.style.position = 'fixed'
  document.body.appendChild(textArea)
  textArea.focus()
  textArea.select()
  document.execCommand('copy')
  document.body.removeChild(textArea)
}
