import { useEffect, useState } from "react"; import { Marker, Tooltip, Polyline, Polygon, Circle } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import { CustomMapContainer } from "@/components/map"; import useAdmin from "@/hook/useAdmin"; import { GameState } from "@/util/gameState"; const positionIcon = new L.Icon({ iconUrl: '/icons/marker/blue.png', iconSize: [30, 30], iconAnchor: [15, 15], popupAnchor: [0, -15], shadowSize: [30, 30], }); const zoneTypes = { circle: "circle", polygon: "polygon" } export default function LiveMap({mapStyle, showZones, showNames, showArrows}) { const { zoneSettings, zoneExtremities, teams, nextZoneDate, getTeam, gameState } = useAdmin(); const [timeLeftNextZone, setTimeLeftNextZone] = useState(null); // Remaining time before sending position useEffect(() => { if (nextZoneDate) { const updateTime = () => { setTimeLeftNextZone(Math.max(0, Math.floor((nextZoneDate - Date.now()) / 1000))); }; updateTime(); const interval = setInterval(updateTime, 1000); return () => clearInterval(interval); } }, [nextZoneDate]); function formatTime(time) { // time is in seconds if (time < 0) return "00:00"; const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); return String(minutes).padStart(2,"0") + ":" + String(seconds).padStart(2,"0"); } function Arrow({pos1, pos2}) { if (pos1 && pos2) { return ( ) } else { return null; } } function Zones() { if (!(showZones && gameState == GameState.PLAYING && zoneSettings)) return null; switch (zoneSettings.type) { case zoneTypes.circle: return (
{ zoneExtremities.begin && } { zoneExtremities.end && }
); case zoneTypes.polygon: return (
{ zoneExtremities.begin && } { zoneExtremities.end && }
); default: return null; } } return (
{gameState == GameState.PLAYING &&

{`Next zone in : ${formatTime(timeLeftNextZone)}`}

} {teams.map((team) => team.currentLocation && !team.captured && {showNames && {team.name}} {showArrows && } )}
) }