import React from 'react' import type { ItemStack } from '../../types' import { MessageFormattedString } from '../Text/MessageFormattedString' import styles from './Tooltip.module.css' function getRarityColor(item: ItemStack): string { if (item.enchantments && item.enchantments.length > 0) return '#8080ff' return '#ffffff' } function formatEnchantment(e: { name: string; level: number }): string { const roman = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'] return e.level <= 10 ? `${e.name} ${roman[e.level]}` : `${e.name} ${e.level}` } export function getItemTooltipDisplayName(item: ItemStack): string { return item.displayName ?? (item.name ? item.name.replace(/_/g, ' ') : `Item #${item.type}`) } /** Item name, enchantments, lore, durability, and type id — shared by desktop tooltip and mobile menu. */ export function ItemTooltipBody({ item }: { item: ItemStack }) { const nameColor = getRarityColor(item) const hasDurability = item.durability !== undefined && item.maxDurability !== undefined && item.durability < item.maxDurability return ( <>
{item.enchantments && item.enchantments.length > 0 && (
{item.enchantments.map((e, i) => (
{formatEnchantment(e)}
))}
)} {item.lore && item.lore.length > 0 && (
{item.lore.map((line, i) => (
))}
)} {hasDurability && (
Durability: {item.durability} / {item.maxDurability}
)}
{item.name ?? `#${item.type}`} {item.metadata !== undefined && item.metadata > 0 ? `:${item.metadata}` : ''}
) }