import { useEffect, useState } from "react"; import { Marker, Tooltip, Polygon, Circle } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import 'leaflet-polylinedecorator'; import { Arrow } from "@/components/layer"; import { CustomMapContainer, MapEventListener, MapPan } from "@/components/map"; import useAdmin from "@/hook/useAdmin"; import { GameState, ZoneTypes } from "@/util/types"; import { mapZooms } from "@/util/configurations"; const positionIcon = new L.Icon({ iconUrl: '/icons/marker/blue.png', iconSize: [30, 30], iconAnchor: [15, 15], popupAnchor: [0, -15], shadowSize: [30, 30], }); export default function LiveMap({ selectedTeamId, onSelected, isFocusing, setIsFocusing, mapStyle, showZones, showNames, showArrows}) { const { zoneType, 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 Zones() { if (!(showZones && gameState == GameState.PLAYING && zoneType)) return null; switch (zoneType) { 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)}`}

} {isFocusing && } setIsFocusing(false)}/> {teams.map((team) => gameState == GameState.PLACEMENT && team.startingArea && {team.name} )} {teams.map((team) => team.currentLocation && !team.captured && <> onSelected(team.id)}}> {showNames && {team.name}} {showArrows && } )}
) }