'use client'; import { useState } from 'react'; import { createPortal } from 'react-dom'; import { motion, AnimatePresence } from 'motion/react'; import { useEffect, useRef } from 'react'; interface PlayerTooltipProps { playerName: string; children: React.ReactNode; } // Get Minecraft skin URL (using Minotar API) const getMinecraftSkinUrl = (username: string) => { // Minotar provides avatar images - use /avatar/ for head only or /helm/avatar/ for head with helm return `https://minotar.net/avatar/${encodeURIComponent(username)}/64`; }; export function PlayerTooltip({ playerName, children }: PlayerTooltipProps) { const [isHovered, setIsHovered] = useState(false); const [position, setPosition] = useState({ top: 0, left: 0 }); const triggerRef = useRef(null); useEffect(() => { const updatePosition = () => { if (triggerRef.current) { // Find the actual child element (the

tag) to get its position const childElement = triggerRef.current.firstElementChild as HTMLElement; if (childElement) { const rect = childElement.getBoundingClientRect(); setPosition({ top: rect.top - 90, // Position above the element (accounting for tooltip height) left: rect.left + rect.width / 2, }); } } }; if (isHovered) { // Small delay to ensure DOM is ready const timeoutId = setTimeout(updatePosition, 0); window.addEventListener('scroll', updatePosition, true); window.addEventListener('resize', updatePosition); return () => { clearTimeout(timeoutId); window.removeEventListener('scroll', updatePosition, true); window.removeEventListener('resize', updatePosition); }; } }, [isHovered]); const tooltipContent = ( {isHovered && typeof window !== 'undefined' && (

{`${playerName}'s
{playerName}
)} ); return ( <>
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} style={{ display: 'inline' }} > {children}
{typeof window !== 'undefined' && createPortal(tooltipContent, document.body)} ); }