"use client"; import { TibiaItem } from "@/types/item"; import { MagicCard } from "@/components/ui/magic-card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { PriceDisplay } from "@/components/ui/price-display"; import { useTranslations } from "next-intl"; import { TrendingUp, TrendingDown, Sword, Shield, Weight, Heart, Star, Clock, Coins, ArrowUp, ArrowDown, Minus, Zap, Flame, Snowflake, Zap as Energy, Skull, Cross, Badge as BadgeIcon, Boxes, } from "lucide-react"; import { useState } from "react"; import { getRarityColor, getRarityBgColor, getRarityGlow, } from "@/lib/currency-utils"; interface ItemCardProps { item: TibiaItem; mode?: "market" | "catalog"; } export function ItemCard({ item, mode = "market" }: ItemCardProps) { const t = useTranslations("home.item"); const [isFavorited, setIsFavorited] = useState(false); const [isHovered, setIsHovered] = useState(false); const rarityColors = { common: "bg-gray-500", uncommon: "bg-green-500", rare: "bg-blue-500", epic: "bg-purple-500", legendary: "bg-orange-500", }; const categoryIcons = { weapon: Sword, armor: Shield, helmet: Shield, legs: Shield, boots: Shield, shield: Shield, amulet: "💎", ring: "💍", potion: "🧪", rune: "📜", tool: "🔧", ammunition: "🏹", other: "📦", }; const CategoryIcon = categoryIcons[item.category]; // Calcular diferença percentual entre compra e venda (somente quando houver preço) const hasPrice = item && (item as any).price && typeof (item as any).price.buy === "number" && typeof (item as any).price.sell === "number" && (item as any).price.sell !== 0; const priceDifference = hasPrice ? (((item as any).price.buy - (item as any).price.sell) / (item as any).price.sell) * 100 : 0; const isHotDeal = hasPrice && priceDifference > 20; // Hot deal se diferença > 20% // Determinar tendência de preço const getPriceTrend = () => { const ph = (item as any).priceHistory; if (!ph || typeof ph.highest !== "number" || typeof ph.lowest !== "number" || typeof ph.average !== "number") { return "stable"; } if (ph.highest > ph.average * 1.1) return "up"; if (ph.lowest < ph.average * 0.9) return "down"; return "stable"; }; const trend = getPriceTrend(); const TrendIcon = trend === "up" ? ArrowUp : trend === "down" ? ArrowDown : Minus; const trendColor = trend === "up" ? "text-green-500" : trend === "down" ? "text-red-500" : "text-gray-500"; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {/* Header com ícone e badge de raridade */}
{/* Badge de raridade com glow (apenas em modo market) */} {mode === "market" && ( {item.rarity} )} {/* Botão de favorito */} {/* Hot Deal Badge (apenas em modo market) */} {mode === "market" && isHotDeal && ( 🔥 Hot Deal )} {/* Imagem real do item (se disponível) ou ícone por categoria */}
{item.image ? ( // eslint-disable-next-line @next/next/no-img-element {item.name} { (e.currentTarget as HTMLImageElement).style.display = "none"; }} /> ) : (
{typeof CategoryIcon === "string" ? ( CategoryIcon ) : ( )}
)}
{/* Conteúdo do card */}
{/* Nome do item */}

{item.name}

{/* Timestamp */}
Atualizado há 5 min
{/* Estatísticas agrupadas */} {item.stats && (
{item.stats.attack && (
⚔️ {item.stats.attack} ATK
)} {item.stats.defense && (
🛡️ {item.stats.defense} DEF
)} {item.stats.armor && (
🛡️ {item.stats.armor} ARM
)}
{/* Proteções elementais */} {item.protections && (
{item.protections.fire && (
🔥 Fire +{item.protections.fire}%
)} {item.protections.ice && (
❄️ Ice +{item.protections.ice}%
)} {item.protections.energy && (
⚡ Energy +{item.protections.energy}%
)}
)} {/* Requisitos */} {item.requirements && (
{item.requirements.level && (
Lvl {item.requirements.level}+
)} {(item as any).requirements?.skill && (
{(item as any).requirements.skill}
)} {item.requirements.vocation && (
👤 Best for {item.requirements.vocation}
)}
)} {item.stats.weight && (
⚖️ {item.stats.weight} oz
)} {(item as any).stats?.slots && (
Slots {(item as any).stats?.slots}
)}
)} {mode === "market" && item.price && ( <> {/* Divisor visual */}
{/* Preços com ícones e formatação melhorada */}
{t("buyPrice")}
{t("sellPrice")}
{/* Diferença percentual */}
0 ? "text-green-600" : "text-red-600" }`} > {priceDifference > 0 ? "+" : ""} {priceDifference.toFixed(1)}% diferença
)} {mode === "market" && item.priceHistory && ( <> {/* Divisor visual */}
{/* Histórico de preço com sparkline */}
{t("priceHistory")}
{trend}
{t("highest")}
🪙 {item.priceHistory.highest.toLocaleString()} gp
{t("lowest")}
🪙 {item.priceHistory.lowest.toLocaleString()} gp
{t("average")}
🪙 {item.priceHistory.average.toLocaleString()} gp
)} {mode === "market" && (
)}
); }