/** Region presentation + geo constants for the Network screen. */

/** Flag emoji per region code (presentation only; falls back to 🌐). */
export const FLAGS: Record<string, string> = {
    KE: '🇰🇪', US: '🇺🇸', UK: '🇬🇧', GB: '🇬🇧', IN: '🇮🇳', NG: '🇳🇬', ZA: '🇿🇦',
    UG: '🇺🇬', MW: '🇲🇼', TZ: '🇹🇿', GH: '🇬🇭', ET: '🇪🇹', RW: '🇷🇼', ZM: '🇿🇲',
    EG: '🇪🇬', FR: '🇫🇷', DE: '🇩🇪', NL: '🇳🇱', BR: '🇧🇷', AU: '🇦🇺', CA: '🇨🇦',
    SG: '🇸🇬', AE: '🇦🇪', Global: '🌐',
};

/**
 * Fallback [lon, lat] centroid per region code. Used ONLY when a region's
 * monitors have no resolved geo (private IPs / internal hosts) — real markers
 * are placed at each monitor's actual resolved coordinate. Approximate
 * country centroids, good enough to land the marker on the right landmass.
 */
export const COUNTRY_CENTROIDS: Record<string, [number, number]> = {
    US: [-98, 39], CA: [-106, 56], BR: [-52, -10],
    UK: [-2, 54], GB: [-2, 54], FR: [2.5, 46], DE: [10, 51], NL: [5.7, 52],
    KE: [38, 0.5], UG: [32, 1.3], TZ: [35, -6], RW: [29.9, -1.9],
    ET: [40, 9], NG: [8, 9], GH: [-1, 7.9], ZA: [24, -29], MW: [34, -13.2],
    ZM: [27.8, -13.1], EG: [30, 26],
    IN: [79, 22], SG: [103.8, 1.35], AE: [54, 24], AU: [134, -25],
    Global: [-22, 28],
};

/**
 * Map our country display names (prisma Country.name / mock) to the
 * Natural Earth `properties.name` used by world-atlas, for the handful of
 * names that differ. Best-effort: highlighting the selected country polygon
 * is polish — the zoom itself targets the monitors' real coordinates, so an
 * unmatched name still zooms correctly.
 */
const NAME_ALIASES: Record<string, string> = {
    'united states': 'United States of America',
    'usa': 'United States of America',
    'uk': 'United Kingdom',
    'tanzania': 'United Republic of Tanzania',
    'democratic republic of the congo': 'Dem. Rep. Congo',
    'republic of the congo': 'Congo',
    "cote d'ivoire": "Côte d'Ivoire",
    'ivory coast': "Côte d'Ivoire",
    'south korea': 'South Korea',
    'czech republic': 'Czechia',
    'global': '',
    'global (all regions)': '',
    'global / cdn': '',
};

/** Normalise a country display name to compare against a topojson feature name. */
export function matchCountryName(displayName: string): string {
    const key = displayName.trim().toLowerCase();
    return (NAME_ALIASES[key] ?? displayName.trim()).toLowerCase();
}
