"use client"; import { forwardRef, useMemo, useImperativeHandle, useRef } from "react"; import { Tournament } from "@/types"; import L from "leaflet"; import { Marker, Popup, MarkerProps } from "react-leaflet"; import { useTranslations } from "next-intl"; import { useSetAtom } from "jotai"; import { FaTrophy } from "react-icons/fa"; import { last } from "lodash"; import type { BouncingMarker } from "@/leafletTypes"; import { debouncedHoveredMapTournamentGroupIdAtom } from "@/app/atoms"; import { TimeControlColours } from "@/app/constants"; export type TournamentMarkerRef = { getMarker: () => L.Marker; bounce: () => void; }; type TournamentMarkerProps = { tournamentGroup: Tournament[]; } & Omit; export const TournamentMarker = forwardRef< TournamentMarkerRef, TournamentMarkerProps >(({ tournamentGroup, ...markerProps }, ref) => { const t = useTranslations("Tournaments"); const markerRef = useRef | null>(null); useImperativeHandle( ref, () => ({ getMarker: () => markerRef.current!, bounce: () => { const bouncingMarker = markerRef.current as BouncingMarker; bouncingMarker.setBouncingOptions({ contractHeight: 0 }); bouncingMarker.bounce(); }, }), [], ); const { date, latLng, groupId, timeControl } = tournamentGroup[0]; const setHoveredMapTournamentGroupId = useSetAtom( debouncedHoveredMapTournamentGroupIdAtom, ); const iconOptions = useMemo( () => new L.DivIcon({ html: ` `, className: timeControl, iconSize: [24, 40], iconAnchor: [12, 40], popupAnchor: [1, -40], }), [timeControl], ); const startDate = date; const endDate = last(tournamentGroup)!.date; return ( setHoveredMapTournamentGroupId(groupId), mouseout: () => setHoveredMapTournamentGroupId(null), }} {...markerProps} >
{date} {endDate !== startDate && ` - ${endDate}`}
{tournamentGroup.map((tournament) => ( {tournament.tournament} ))}
{tournamentGroup.some((t) => t.norm) && (
{t("norm")}
)} {t("approx")}
); }); TournamentMarker.displayName = "TournamentMarker";