"use client"; import { countryCodeMapping } from "@/lib/geo"; import { geoEquirectangular, geoPath } from "d3-geo"; import { AnimatePresence, m } from "framer-motion"; import { useTranslations } from "next-intl"; import { useState } from "react"; interface InteractiveMapProps { countries: string[]; serverCounts: { [key: string]: number }; width: number; height: number; filteredFeatures: any[]; } export function InteractiveMap({ countries, serverCounts, width, height, filteredFeatures, }: InteractiveMapProps) { const t = useTranslations("Global"); const [tooltipData, setTooltipData] = useState<{ centroid: [number, number]; country: string; count: number; } | null>(null); const countries_alpha3 = countries .map((code) => countryCodeMapping[code]) .filter((code) => code !== undefined); const projection = geoEquirectangular() .scale(140) .translate([width / 2, height / 2]) .rotate([-12, 0, 0]); const path = geoPath().projection(projection); return (
{filteredFeatures.map((feature, index) => { const isHighlighted = countries_alpha3.includes( feature.properties.iso_a3, ); const countryCode = Object.entries(countryCodeMapping).find( ([, alpha3]) => alpha3 === feature.properties.iso_a3, )?.[0]; const serverCount = countryCode ? serverCounts[countryCode] || 0 : 0; return ( { if (isHighlighted && path.centroid(feature)) { setTooltipData({ centroid: path.centroid(feature), country: feature.properties.name, count: serverCount, }); } }} onMouseLeave={() => setTooltipData(null)} /> ); })} {tooltipData && (

{tooltipData.country}

{tooltipData.count} {t("Servers")}

)}
); }