import React, { useState } from 'react'; interface MetricDetailTooltipProps { children: React.ReactNode; currentValue: number; previousValue: number; yoyValue: number; currentWeekLabel: string; previousWeekLabel: string; yoyWeekLabel: string; metricName: string; metricColor: string; formatValue?: (val: number) => string; experimentDelta?: number | null; baselineValue?: number | null; } /** * Tooltip component to show comparison details on hover (WoW and YoY). * Extracted from WeeklyGrid to prevent circular dependencies and initialization errors. */ export const MetricDetailTooltip: React.FC = ({ children, currentValue, previousValue, yoyValue, currentWeekLabel, previousWeekLabel, yoyWeekLabel, metricName, metricColor, formatValue, experimentDelta, baselineValue }) => { const [isVisible, setIsVisible] = useState(false); const wowGrowth = previousValue > 0 ? ((currentValue - previousValue) / previousValue) * 100 : (currentValue > 0 ? 100 : 0); const yoyGrowth = yoyValue > 0 ? ((currentValue - yoyValue) / yoyValue) * 100 : null; const format = formatValue || ((v: number) => v.toLocaleString('de-DE')); const hasYoyData = yoyValue > 0; return (
setIsVisible(true)} onMouseLeave={() => setIsVisible(false)} >
{children}
{isVisible && (
📊 {metricName} Comparison
{/* Current Week */}
{currentWeekLabel} {format(currentValue)}
{/* Previous Week */}
{previousWeekLabel} {previousValue > 0 ? format(previousValue) : 'N/A'}
{/* Same Week Last Year */}
{yoyWeekLabel} {hasYoyData ? format(yoyValue) : 'No data'}
{/* WoW Growth */}
vs Previous Week {previousValue > 0 ? ( = 0 ? 'text-emerald-400' : 'text-red-400'}`}> {wowGrowth >= 0 ? 'â–²' : 'â–¼'} {Math.abs(wowGrowth).toFixed(1)}% ) : ( N/A )}
{/* YoY Growth */}
vs Same Week Last Year {yoyGrowth !== null ? ( = 0 ? 'text-emerald-400' : 'text-red-400'}`}> {yoyGrowth >= 0 ? 'â–²' : 'â–¼'} {Math.abs(yoyGrowth).toFixed(1)}% ) : ( No data )}
{/* Experiment Baseline Delta (If active) */} {typeof experimentDelta === 'number' && typeof baselineValue === 'number' && (
vs Pre-Experiment Baseline = 0 ? 'text-emerald-400' : 'text-red-400'}`}> {experimentDelta >= 0 ? 'â–²' : 'â–¼'} {Math.abs(experimentDelta).toFixed(1)}%
Baseline Avg (4w) {format(baselineValue)}
)}
{/* Arrow */}
)}
); };