import { toast } from "sonner"; function copyTextWithExecCommand(text: string): boolean { try { const textarea = document.createElement("textarea"); textarea.value = text; textarea.setAttribute("readonly", ""); textarea.style.position = "fixed"; textarea.style.left = "-9999px"; textarea.style.top = "0"; document.body.appendChild(textarea); textarea.focus({ preventScroll: true }); textarea.select(); textarea.setSelectionRange(0, text.length); const ok = document.execCommand("copy"); document.body.removeChild(textarea); return ok; } catch { return false; } } export async function copyTextWithAttachments(text: string): Promise { try { await navigator.clipboard.writeText(text); return true; } catch { if (copyTextWithExecCommand(text)) { return true; } toast.error("Copy error", { description: "Failed to copy prompt to clipboard", }); return false; } }