"use client"; import { ConversationSummary } from "@/features/agent/types"; import { buildMessagePreview, formatConversationTime, isVisitorOnline, } from "@/utils/format"; import { Badge } from "@/components/ui/badge"; import { Card } from "@/components/ui/card"; interface ConversationListItemProps { conversation: ConversationSummary; selected: boolean; onSelect: (id: number) => void; } export function ConversationListItem({ conversation, selected, onSelect, }: ConversationListItemProps) { const avatarColor = `hsl(${(conversation.id * 137.5) % 360}, 70%, 50%)`; const unreadCount = conversation.unread_count ?? 0; const lastMessage = conversation.last_message; const lastMessagePreview = lastMessage ? buildMessagePreview(lastMessage.content) : "暂无消息"; // 根据 last_seen_at 判断是否在线(最近 10 秒内认为在线) const isOnline = isVisitorOnline(conversation.last_seen_at); return ( { event.preventDefault(); event.stopPropagation(); onSelect(conversation.id); }} onMouseDown={(event) => { if (event.button === 0) { event.preventDefault(); } }} className={`p-4 mb-2 cursor-pointer transition-all select-none border border-border shadow-sm hover:shadow-md ${ selected ? "bg-primary/5 border-l-4 border-l-primary shadow-md" : "hover:bg-accent/50" }`} >
{conversation.visitor_id.toString().slice(-2)}
对话 #{conversation.id} {/* 在线/离线状态图标 */} {isOnline && ( )} {unreadCount > 0 && ( {unreadCount > 99 ? "99+" : unreadCount} )} {conversation.status === "open" ? "进行中" : "已关闭"}
{lastMessage?.sender_is_agent && ( {lastMessage.is_read ? "✓✓" : "✓"} )} {lastMessagePreview}
访客 #{conversation.visitor_id} {formatConversationTime(conversation.updated_at)}
); }