import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Copy, FileJson, FileText, MoreHorizontal, Contrast } from "lucide-react"; import { useEffect, useState } from "react"; interface MessageActionsProps { content: string; role: string; } export function MessageActions({ content, role }: MessageActionsProps) { const [copied, setCopied] = useState(false); const [highContrast, setHighContrast] = useState(false); useEffect(() => { const saved = typeof window !== 'undefined' ? localStorage.getItem('highContrast') === 'true' : false; setHighContrast(saved); if (typeof document !== 'undefined') { if (saved) document.documentElement.setAttribute('data-high-contrast', 'true'); else document.documentElement.removeAttribute('data-high-contrast'); } }, []); const handleCopy = (text: string) => { navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const copyMarkdown = () => handleCopy(content); const copyText = () => { // Simple strip markdown (can be improved with a library if needed) const text = content .replace(/#{1,6}\s/g, '') // Headers .replace(/(\*\*|__)(.*?)\1/g, '$2') // Bold .replace(/(\*|_)(.*?)\1/g, '$2') // Italic .replace(/`{3}[\s\S]*?`{3}/g, '$&') // Keep code blocks but maybe strip fences? For now keep raw .replace(/`(.+?)`/g, '$1') // Inline code .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1 ($2)') // Links .replace(/>\s/g, ''); // Blockquotes handleCopy(text); }; const copyJson = () => { const json = JSON.stringify({ role, content }, null, 2); handleCopy(json); }; return (
Copiar Texto Puro Copiar JSON { const next = !highContrast; setHighContrast(next); if (typeof document !== 'undefined') { if (next) document.documentElement.setAttribute('data-high-contrast', 'true'); else document.documentElement.removeAttribute('data-high-contrast'); } if (typeof window !== 'undefined') { localStorage.setItem('highContrast', String(next)); } }} > {highContrast ? 'Desativar Alto Contraste' : 'Ativar Alto Contraste'}
); }