// React
import { useMemo } from 'react';
import { StyleSheet, View, TouchableOpacity, Image, Text, Alert } from 'react-native';
import { useTranslation } from 'react-i18next';
// Contexts
import { useTeam } from '@/contexts/teamContext';
// Hook
import { useTimeSinceSeconds } from '@/hooks/useTimeDelta';
// Util
import { secondsToHHMMSS } from '@/utils/functions';
const Stat = ({ children, source, description }) => {
const { t } = useTranslation();
return (
Alert.alert(t("info.default.title"), description) : null}>
{children}
);
};
export const TeamStats = () => {
const { t } = useTranslation();
const { teamInfos, startDate } = useTeam();
const { distance, finishDate, nCaptures, nSentLocation } = teamInfos;
const timeSinceGameStart = useTimeSinceSeconds(startDate);
const avgSpeed = useMemo(() => {
const hours = (finishDate ? (finishDate - startDate) : timeSinceGameStart*1000) / 1000 / 3600;
if (hours <= 0 || distance <= 0) return 0;
const km = distance / 1000;
const speed = km / hours;
return parseFloat(speed.toFixed(1));
}, [finishDate, startDate, timeSinceGameStart, distance]);
return (
{t("play.drawer.stats_section_title")}
{Math.floor((distance ?? 0) / 100) / 10}km
{secondsToHHMMSS((finishDate ? Math.floor((finishDate - startDate) / 1000) : timeSinceGameStart))}
{avgSpeed}km/h
{nCaptures ?? 0}
{nSentLocation ?? 0}
);
};
const styles = StyleSheet.create({
statsContainer: {
width: "100%",
gap: 15,
},
title: {
fontSize: 20,
fontWeight: "bold",
textAlign: "center",
},
row: {
flexDirection: "row",
justifyContent: "space-around",
},
statContainer: {
flexDirection: "row",
justifyContent: 'center',
alignItems: 'center',
gap: 5,
},
image: {
width: 30,
height: 30,
},
text: {
fontSize: 15,
},
});