import React, { useState } from 'react'; import { Button } from './ui/button'; import { Copy, ThumbsUp, ThumbsDown, ChevronDown, ChevronUp, Check, Bot } from 'lucide-react'; import { Badge } from './ui/badge'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from './ui/dialog'; import { Textarea } from './ui/textarea'; import { Label } from './ui/label'; import type { Message as MessageType } from '../App'; import { toast } from 'sonner@2.0.3'; interface MessageProps { message: MessageType; showSenderInfo?: boolean; // For group chat mode } export function Message({ message, showSenderInfo = false }: MessageProps) { const [feedback, setFeedback] = useState<'helpful' | 'not-helpful' | null>(null); const [copied, setCopied] = useState(false); const [referencesOpen, setReferencesOpen] = useState(false); const [showFeedbackDialog, setShowFeedbackDialog] = useState(false); const [feedbackType, setFeedbackType] = useState<'helpful' | 'not-helpful' | null>(null); const [feedbackText, setFeedbackText] = useState(''); const isUser = message.role === 'user'; const handleCopy = async () => { await navigator.clipboard.writeText(message.content); setCopied(true); toast.success('Message copied to clipboard'); setTimeout(() => setCopied(false), 2000); }; const handleFeedback = (type: 'helpful' | 'not-helpful') => { setFeedback(type); toast.success(`Thanks for your feedback!`); }; const handleFeedbackDialogOpen = (type: 'helpful' | 'not-helpful') => { setFeedbackType(type); setShowFeedbackDialog(true); }; const handleFeedbackDialogClose = () => { setShowFeedbackDialog(false); setFeedbackType(null); setFeedbackText(''); }; const handleFeedbackDialogSubmit = () => { if (feedbackType) { setFeedback(feedbackType); toast.success(`Thanks for your feedback!`); } handleFeedbackDialogClose(); }; return (
{message.content}