"use client"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; interface GeographicThreatMapProps { geoDistribution: Record; title?: string; } // Simple country code to name mapping for common countries const countryNames: Record = { USA: "United States", GBR: "United Kingdom", DEU: "Germany", FRA: "France", JPN: "Japan", CHN: "China", IND: "India", BRA: "Brazil", CAN: "Canada", AUS: "Australia", RUS: "Russia", ESP: "Spain", ITA: "Italy", NLD: "Netherlands", KOR: "South Korea", MEX: "Mexico", CHE: "Switzerland", SWE: "Sweden", NOR: "Norway", DNK: "Denmark", FIN: "Finland", POL: "Poland", BEL: "Belgium", AUT: "Austria", NZL: "New Zealand", SGP: "Singapore", THA: "Thailand", IDN: "Indonesia", MYS: "Malaysia", PHL: "Philippines", VNM: "Vietnam", ARE: "UAE", SAU: "Saudi Arabia", ISR: "Israel", ZAF: "South Africa", EGY: "Egypt", TUR: "Turkey", GRC: "Greece", PRT: "Portugal", CZE: "Czech Republic", HUN: "Hungary", ROU: "Romania", BGR: "Bulgaria", HRV: "Croatia", SVN: "Slovenia", SVK: "Slovakia", EST: "Estonia", LVA: "Latvia", LTU: "Lithuania", LUX: "Luxembourg", MLT: "Malta", CYP: "Cyprus", ISL: "Iceland", IRL: "Ireland", ARG: "Argentina", CHL: "Chile", COL: "Colombia", PER: "Peru", URY: "Uruguay", ECU: "Ecuador", BOL: "Bolivia", PRY: "Paraguay", VEN: "Venezuela", UKR: "Ukraine", BLR: "Belarus", MDA: "Moldova", GEO: "Georgia", ARM: "Armenia", AZE: "Azerbaijan", KAZ: "Kazakhstan", UZB: "Uzbekistan", KGZ: "Kyrgyzstan", TJK: "Tajikistan", TKM: "Turkmenistan", MNG: "Mongolia", }; export function GeographicThreatMap({ geoDistribution, title = "Geographic Threat Distribution", }: GeographicThreatMapProps) { const sortedCountries = Object.entries(geoDistribution) .sort(([, a], [, b]) => b - a) .slice(0, 12); const totalEvents = Object.values(geoDistribution).reduce( (sum, count) => sum + count, 0 ); const getThreatLevel = (count: number, total: number) => { const percentage = (count / total) * 100; if (percentage > 50) return { level: "high", color: "destructive" }; if (percentage > 20) return { level: "medium", color: "secondary" }; if (percentage > 5) return { level: "low", color: "outline" }; return { level: "minimal", color: "outline" }; }; const getCountryName = (code: string) => { return countryNames[code] || code; }; return ( {title} Security events by country ({totalEvents} total events) {sortedCountries.length === 0 ? (

No geographic data available

) : (
{sortedCountries.map(([countryCode, count]) => { const threat = getThreatLevel(count, totalEvents); const percentage = ((count / totalEvents) * 100).toFixed(1); return (
{getCountryName(countryCode)} {threat.level}

{count} events ({percentage}%)

{count}
); })}
{Object.keys(geoDistribution).length > 12 && (

And {Object.keys(geoDistribution).length - 12} more countries...

)}
)} ); }