import React, { useState } from 'react'; import { Scale, User, Copy, Check, ThumbsUp, ThumbsDown, RotateCw, FileText, Clock, Cpu, Share2, Edit3, Trash2 } from 'lucide-react'; import type { Message } from '../types/chat'; interface MessageCardProps { message: Message; onRegenerate?: () => void; onOpenPDFPreview?: (pdf: NonNullable) => void; onEditMessage?: (id: string, text: string) => void; onDeleteMessage?: (id: string) => void; } export const MessageCard: React.FC = ({ message, onRegenerate, onOpenPDFPreview, onEditMessage, onDeleteMessage }) => { const [copied, setCopied] = useState(false); const [liked, setLiked] = useState(null); const [isEditing, setIsEditing] = useState(false); const [editText, setEditText] = useState(message.content); const isUser = message.role === 'user'; const handleCopy = () => { navigator.clipboard.writeText(message.content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const handleSaveEdit = () => { if (onEditMessage && editText.trim()) { onEditMessage(message.id, editText.trim()); setIsEditing(false); } }; // Simple Markdown & Table Parser const renderFormattedContent = (content: string) => { const codeBlockRegex = /```(\w*)\n([\s\S]*?)```/g; const parts = []; let lastIndex = 0; let match; while ((match = codeBlockRegex.exec(content)) !== null) { if (match.index > lastIndex) { parts.push(content.substring(lastIndex, match.index)); } const lang = match[1] || 'code'; const code = match[2].trim(); parts.push(
{lang}
            {code}
          
); lastIndex = match.index + match[0].length; } if (lastIndex < content.length) { parts.push(content.substring(lastIndex)); } return parts.map((p, idx) => { if (typeof p === 'string') { // Simple Markdown Table parsing if (p.includes('|')) { const lines = p.split('\n'); const tableRows = lines.filter(l => l.trim().startsWith('|')); if (tableRows.length > 1) { return (
{tableRows.map((row, rIdx) => { if (row.includes(':---') || row.includes('---')) return null; const cols = row.split('|').filter(c => c.trim() !== ''); return ( {cols.map((cell, cIdx) => ( ))} ); })}
{cell.trim().replace(/\*\*/g, '')}
); } } return

{p}

; } return p; }); }; return (
{/* Header Bar */}
{isUser ? : }
{isUser ? 'You' : 'LawSLM Assistant'}
{message.timestamp}
{/* Content Body */} {isEditing ? (