"use client"; import { Clock, Package } from "lucide-react"; import Image from "next/image"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Card } from "@/components/ui/card"; import type { Chat } from "@/lib/hooks/use-chat"; import { formatTimeAgo } from "@/lib/utils"; interface ChatListItemProps { chat: Chat; currentUserId: number; onChatClick: () => void; } export function ChatListItem({ chat, currentUserId, onChatClick, }: ChatListItemProps) { const otherUser = chat.buyer_id === currentUserId ? chat.seller_cache : chat.buyer_cache; const unreadCount = chat.buyer_id === currentUserId ? chat.buyer_unread_count : chat.seller_unread_count; const listing = chat.listing_cache; return (
{/* Avatar do outro usuário */} {(otherUser.character_name || otherUser.username) .charAt(0) .toUpperCase()} {/* Conteúdo */}

{otherUser.character_name || otherUser.username}

{unreadCount > 0 && ( {unreadCount} )}
{/* Preview do item */}
{listing.item_name}
{/* Preview da última mensagem */} {chat.last_message_preview && (

{chat.last_message_preview}

)} {/* Timestamp */} {chat.last_message_at && (
{formatTimeAgo(new Date(chat.last_message_at))}
)}
{/* Imagem do item (opcional) */} {listing.item_image_url && (
{listing.item_name} { e.currentTarget.style.display = "none"; }} />
)}
); }