'use client' /** * GlossaryTooltip Component * * Displays a term with a hover tooltip that explains the compliance concept. * Supports bilingual content (DE/EN) from the i18n system. */ import { useState, useRef, useEffect } from 'react' import { getTerm, getDescription, Language } from '@/lib/compliance-i18n' interface GlossaryTooltipProps { termKey: string lang?: Language children?: React.ReactNode className?: string showIcon?: boolean } export default function GlossaryTooltip({ termKey, lang = 'de', children, className = '', showIcon = true, }: GlossaryTooltipProps) { const [isVisible, setIsVisible] = useState(false) const [position, setPosition] = useState<'top' | 'bottom'>('top') const triggerRef = useRef(null) const tooltipRef = useRef(null) const term = getTerm(lang, termKey) const description = getDescription(lang, termKey) useEffect(() => { if (isVisible && triggerRef.current && tooltipRef.current) { const triggerRect = triggerRef.current.getBoundingClientRect() const tooltipHeight = tooltipRef.current.offsetHeight const spaceAbove = triggerRect.top const spaceBelow = window.innerHeight - triggerRect.bottom // Position tooltip where there's more space if (spaceAbove < tooltipHeight + 10 && spaceBelow > spaceAbove) { setPosition('bottom') } else { setPosition('top') } } }, [isVisible]) if (!description) { // No description available, just render the term return {children || term} } return ( setIsVisible(true)} onMouseLeave={() => setIsVisible(false)} onFocus={() => setIsVisible(true)} onBlur={() => setIsVisible(false)} tabIndex={0} > {children || term} {showIcon && ( )} {/* Tooltip */} {isVisible && (
{/* Arrow */}
{/* Content */}
{term}
{description}
)} ) } /** * InfoIcon Component * * A standalone info icon that shows a tooltip on hover. */ interface InfoIconProps { text: string className?: string } export function InfoIcon({ text, className = '' }: InfoIconProps) { const [isVisible, setIsVisible] = useState(false) return ( setIsVisible(true)} onMouseLeave={() => setIsVisible(false)} > {isVisible && (
{text}
)} ) }