"use client"; import { Coins, DollarSign, MapPin, Package, User } from "lucide-react"; import Image from "next/image"; import { useState } from "react"; import { Badge } from "@/components/ui/badge"; import type { Chat } from "@/lib/hooks/use-chat"; interface ChatHeaderProps { chat: Chat; currentUserId: number; } export function ChatHeader({ chat, currentUserId }: ChatHeaderProps) { const listing = chat.listing_cache; const otherUser = chat.buyer_id === currentUserId ? chat.seller_cache : chat.buyer_cache; const [imageError, setImageError] = useState(false); const formatPrice = ( price: number | null | undefined, type: "pix" | "tc" | "gp", ): string => { if (price === null || price === undefined) return "N/A"; if (type === "pix") { return new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL", }).format(price); } if (type === "tc") { return `${price.toLocaleString("pt-BR")} TC`; } if (type === "gp") { const gold = price / 1000000; if (gold >= 1) { return `${gold.toFixed(2)}kk`; } return `${price.toLocaleString("pt-BR")} gp`; } return price.toLocaleString("pt-BR"); }; return (
{/* Informações do Anúncio */}
{/* Imagem do item */}
{listing.item_image_url && !imageError ? ( {listing.item_name} setImageError(true)} /> ) : ( )}
{/* Detalhes do anúncio */}

{listing.item_name}

{listing.server_name}
Qtd: 1
{/* Preços */}
{listing.price_pix && ( {formatPrice(listing.price_pix, "pix")} )} {listing.price_tibia_coins && ( {formatPrice(listing.price_tibia_coins, "tc")} )} {listing.price_gold_coins && ( {formatPrice(listing.price_gold_coins, "gp")} )}
{/* Informações do outro usuário */}
Conversando com: {otherUser.character_name || otherUser.username}
); }