import React, { useState } from 'react'; import { motion } from 'framer-motion'; import ReactMarkdown from 'react-markdown'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { oneDark, oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism'; import remarkGfm from 'remark-gfm'; import { ClipboardIcon, CheckIcon } from '@heroicons/react/24/outline'; const MessageBubble = ({ message, darkMode, isLast = false }) => { const [copied, setCopied] = useState(false); const copyToClipboard = async (text) => { try { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error('Failed to copy text: ', err); } }; const formatTimestamp = (timestamp) => { const date = new Date(timestamp); return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }); }; return (
{/* Avatar and Timestamp - Mobile optimized */}
{message.role === 'assistant' && (
)} {message.role === 'user' ? 'You' : 'CA Assistant'} {formatTimestamp(message.timestamp)} {message.role === 'user' && (
)}
{/* Message Content - Mobile optimized */}
{/* Message Text - Mobile optimized */}
{message.role === 'user' ? (

{message.content}

) : (
{match[1]}
{String(children).replace(/\n$/, '')}
) : ( {children} ); }, // Mobile-optimized paragraphs p: ({ children }) => (

{children}

), // Mobile-optimized lists ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), // Mobile-optimized headings h1: ({ children }) => (

    {children}

    ), h2: ({ children }) => (

    {children}

    ), h3: ({ children }) => (

    {children}

    ), // Mobile-optimized blockquotes blockquote: ({ children }) => (
    {children}
    ), // Mobile-optimized tables table: ({ children }) => (
    {children}
    ), th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ), }} > {message.content || '*Thinking...*'} )}
    {/* Copy Button for Assistant Messages - Mobile optimized */} {message.role === 'assistant' && message.content && ( )}
    {/* Message tail/pointer - Mobile optimized */}
    ); }; export default MessageBubble;