import { env } from 'next-runtime-env'; import { useEffect, useState } from "react"; import useAdmin from "@/hook/useAdmin"; import { getStatus } from '@/util/functions'; import { Colors, GameState } from '@/util/types'; function DotLine({ label, value }) { return (
{label} {value}
); } function IconValue({ color, icon, value }) { return (

{value}

); } export default function TeamSidePanel({ selectedTeamId, onClose }) { const { getTeam, startDate, gameState } = useAdmin(); const [imgSrc, setImgSrc] = useState(""); const [_, setRefreshKey] = useState(0); const team = getTeam(selectedTeamId); const NO_VALUE = "XX"; const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST"); const SERVER_URL = (NEXT_PUBLIC_SOCKET_HOST == "localhost" ? "http://" : "https://") + NEXT_PUBLIC_SOCKET_HOST + "/back"; useEffect(() => { setImgSrc(`${SERVER_URL}/photo/my?team=${selectedTeamId}&t=${Date.now()}`); }, [selectedTeamId]); if (!team) return null; useEffect(() => { const interval = setInterval(() => { setRefreshKey(prev => prev + 1); }, 1000); return () => clearInterval(interval); }, []); function formatTime(startDate, endDate) { // startDate in milliseconds if (endDate == null || startDate == null || startDate < 0) return NO_VALUE + ":" + NO_VALUE; const seconds = Math.floor((endDate - startDate) / 1000); const m = Math.floor(seconds / 60); const s = Math.floor(seconds % 60); return `${m}:${s.toString().padStart(2, "0")}`; } function formatDistance(distance) { // distance in meters if (distance == null || distance < 0) return NO_VALUE + "km"; return `${Math.floor(distance / 100) / 10}km`; } function formatSpeed(distance, startDate, endDate) { // distance in meters | startDate in milliseconds if (distance == null || distance < 0 || endDate == null || startDate == null || endDate <= startDate) return NO_VALUE + "km/h"; const speed = distance / (endDate - startDate); return `${Math.floor(speed * 36000) / 10}km/h`; } function formatDate(date) { // date in milliseconds const dateNow = Date.now(); if (date == null || dateNow <= date || dateNow - date >= 1_000_000) return NO_VALUE + "s"; return `${Math.floor((dateNow - date) / 1000)}s`; } return (

{getStatus(team, gameState).label}

{team.name ?? NO_VALUE}

Photo de l'équipe
0 ? "green" : "red"} icon="user" value={team.sockets?.length ?? NO_VALUE} /> = 20 ? "green" : "red"} icon="battery" value={(team.battery ?? NO_VALUE) + "%"} />
{ gameState != GameState.FINISHED &&
} { (gameState == GameState.PLAYING || gameState == GameState.FINISHED) &&
}
); }