import React, { useEffect, useRef, useState } from 'react'; interface TooltipProps { content: React.ReactNode; children: React.ReactNode; className?: string; position?: 'top' | 'bottom'; } const Tooltip: React.FC = ({ content, children, className = '', position = 'top', }) => { const [isVisible, setIsVisible] = useState(false); const timerRef = useRef | null>(null); const delay = 300; if (!content) { return {children}; } const positionClasses = position === 'top' ? 'bottom-full mb-2 origin-bottom' : 'top-full mt-2 origin-top'; const visibilityClasses = isVisible ? 'opacity-100 scale-100' : 'pointer-events-none opacity-0 scale-95'; const showWithDelay = () => { timerRef.current = setTimeout(() => { setIsVisible(true); }, delay); }; const hideTooltip = () => { if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; } setIsVisible(false); }; useEffect( () => () => { if (timerRef.current) { clearTimeout(timerRef.current); } }, [] ); return ( {children} {content} ); }; export default Tooltip;