import React from 'react'; import { formatTimeOrDate } from 'App/date'; import cn from 'classnames'; import { ArrowUp, ArrowDown } from 'lucide-react'; interface PayloadItem { hide?: boolean; name: string; value: number; prevValue?: number; color?: string; payload?: any; } interface Props { active: boolean; payload: PayloadItem[]; label: string; hoveredSeries?: string | null; } function CustomTooltip(props: Props) { const { active, payload, label, hoveredSeries = null } = props; // Return null if tooltip is not active or there is no valid payload if (!active || !payload?.length || !hoveredSeries) return null; // Find the current and comparison payloads const currentPayload = payload.find((p) => p.name === hoveredSeries); const comparisonPayload = payload.find( (p) => p.name === `${hoveredSeries.replace(' (Comparison)', '')} (Comparison)` || p.name === `${hoveredSeries} (Comparison)` ); if (!currentPayload) return null; // Create transformed array with comparison data const transformedArray = [ { ...currentPayload, prevValue: comparisonPayload ? comparisonPayload.value : null, }, ]; const isHigher = (item: { value: number; prevValue: number }) => item.prevValue !== null && item.prevValue < item.value; const getPercentDelta = (val: number, prevVal: number) => (((val - prevVal) / prevVal) * 100).toFixed(2); return (