import { AverageDefinitionsEntry, formatCompact, type BlitzkitStats, } from '@blitzkit/core'; import { Table } from '@radix-ui/themes'; import { memo, useCallback } from 'react'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio'; import { useLocale } from '../../hooks/useLocale'; import { Performance } from '../../stores/performance'; import { StickyRowHeaderCell } from '../StickyRowHeaderCell'; interface AverageDefinitionsEntryWithId extends AverageDefinitionsEntry { id: number; } interface TotalProps { tanks: AverageDefinitionsEntryWithId[]; } const averageDefinitions = await awaitableAverageDefinitions; export const Total = memo( ({ tanks }) => { const playerCountPeriod = Performance.use( (state) => state.playerCountPeriod, ); const { strings, locale } = useLocale(); const ratio = useAveragesExclusionRatio(); const sum = useCallback( (slice: (tank: BlitzkitStats) => number) => { return tanks.reduce( (acc, tank) => acc + tank.samples[playerCountPeriod] * slice(tank.mu), 0, ); }, [tanks], ); const battles = sum(({ battles }) => battles); const winrate = sum(({ wins }) => wins) / battles; const damage = sum(({ damage_dealt }) => damage_dealt) / battles; const survival = sum(({ survived_battles }) => survived_battles) / battles; const xp = sum(({ xp }) => xp) / battles; const kills = sum(({ frags }) => frags) / battles; const spots = sum(({ spotted }) => spotted) / battles; const hits = sum(({ hits }) => hits) / battles; const shots = sum(({ shots }) => shots) / battles; const accuracy = hits / shots; const damageReceived = sum(({ damage_received }) => damage_received) / battles; const damageRatio = damage / damageReceived; const capturePoints = sum(({ capture_points }) => capture_points) / battles; return ( {strings.website.tools.performance.table.tanks.total} {(winrate * 100).toFixed(1)}% {formatCompact( locale, ratio * averageDefinitions.samples[playerCountPeriod], )} {Math.round(damage).toLocaleString(locale)} {Math.round(survival * 100).toFixed(1)}% {Math.round(xp).toLocaleString(locale)} {kills.toFixed(2)} {spots.toFixed(2)} {(accuracy * 100).toFixed(0)}% {shots.toFixed(1)} {hits.toFixed(1)} {damageRatio.toFixed(2)} {Math.round(damageReceived).toLocaleString(locale)} {capturePoints.toFixed(2)} ); }, (prev, next) => prev.tanks === next.tanks, );