export const TIMEZONE_REGIONS = [
    {
        id: 'global',
        label: 'Global',
        zones: [
            {id: 'UTC', label: 'UTC'},
        ],
    },
    {
        id: 'north-america',
        label: 'North America',
        zones: [
            {id: 'America/Anchorage', label: 'Anchorage'},
            {id: 'America/Los_Angeles', label: 'Los Angeles'},
            {id: 'America/Phoenix', label: 'Phoenix'},
            {id: 'America/Denver', label: 'Denver'},
            {id: 'America/Chicago', label: 'Chicago'},
            {id: 'America/Detroit', label: 'Detroit'},
            {id: 'America/New_York', label: 'New York'},
            {id: 'America/Toronto', label: 'Toronto'},
            {id: 'America/Halifax', label: 'Halifax'},
            {id: 'America/St_Johns', label: "St. John's"},
            {id: 'Pacific/Honolulu', label: 'Honolulu'},
            {id: 'America/Mexico_City', label: 'Mexico City'},
            {id: 'America/Winnipeg', label: 'Winnipeg'},
            {id: 'America/Vancouver', label: 'Vancouver'},
        ],
    },
    {
        id: 'south-america',
        label: 'South America',
        zones: [
            {id: 'America/Panama', label: 'Panama City'},
            {id: 'America/Costa_Rica', label: 'San Jose'},
            {id: 'America/Guatemala', label: 'Guatemala City'},
            {id: 'America/El_Salvador', label: 'San Salvador'},
            {id: 'America/Tegucigalpa', label: 'Tegucigalpa'},
            {id: 'America/Managua', label: 'Managua'},
            {id: 'America/Havana', label: 'Havana'},
            {id: 'America/Santo_Domingo', label: 'Santo Domingo'},
            {id: 'America/Puerto_Rico', label: 'San Juan'},
            {id: 'America/Bogota', label: 'Bogota'},
            {id: 'America/Bogota', label: 'Medellin'},
            {id: 'America/Bogota', label: 'Cali'},
            {id: 'America/Lima', label: 'Lima'},
            {id: 'America/Guayaquil', label: 'Guayaquil'},
            {id: 'America/Guayaquil', label: 'Quito'},
            {id: 'America/Caracas', label: 'Caracas'},
            {id: 'America/Santiago', label: 'Santiago'},
            {id: 'America/La_Paz', label: 'La Paz'},
            {id: 'America/Asuncion', label: 'Asuncion'},
            {id: 'America/Sao_Paulo', label: 'Sao Paulo'},
            {id: 'America/Sao_Paulo', label: 'Rio de Janeiro'},
            {id: 'America/Sao_Paulo', label: 'Brasilia'},
            {id: 'America/Montevideo', label: 'Montevideo'},
            {id: 'America/Buenos_Aires', label: 'Buenos Aires'},
            {id: 'America/Buenos_Aires', label: 'Cordoba'},
            {id: 'America/Buenos_Aires', label: 'Rosario'},
        ],
    },
    {
        id: 'europe',
        label: 'Europe',
        zones: [
            {id: 'Europe/Dublin', label: 'Dublin'},
            {id: 'Europe/London', label: 'London'},
            {id: 'Europe/Lisbon', label: 'Lisbon'},
            {id: 'Europe/Madrid', label: 'Madrid'},
            {id: 'Europe/Paris', label: 'Paris'},
            {id: 'Europe/Brussels', label: 'Brussels'},
            {id: 'Europe/Amsterdam', label: 'Amsterdam'},
            {id: 'Europe/Berlin', label: 'Berlin'},
            {id: 'Europe/Rome', label: 'Rome'},
            {id: 'Europe/Zurich', label: 'Zurich'},
            {id: 'Europe/Vienna', label: 'Vienna'},
            {id: 'Europe/Prague', label: 'Prague'},
            {id: 'Europe/Warsaw', label: 'Warsaw'},
            {id: 'Europe/Athens', label: 'Athens'},
            {id: 'Europe/Helsinki', label: 'Helsinki'},
            {id: 'Europe/Bucharest', label: 'Bucharest'},
            {id: 'Europe/Kyiv', label: 'Kyiv'},
            {id: 'Europe/Istanbul', label: 'Istanbul'},
            {id: 'Europe/Moscow', label: 'Moscow'},
        ],
    },
    {
        id: 'africa-middle-east',
        label: 'Africa / Middle East',
        zones: [
            {id: 'Africa/Casablanca', label: 'Casablanca'},
            {id: 'Africa/Algiers', label: 'Algiers'},
            {id: 'Africa/Tunis', label: 'Tunis'},
            {id: 'Africa/Khartoum', label: 'Khartoum'},
            {id: 'Africa/Lagos', label: 'Lagos'},
            {id: 'Africa/Accra', label: 'Accra'},
            {id: 'Africa/Addis_Ababa', label: 'Addis Ababa'},
            {id: 'Africa/Johannesburg', label: 'Johannesburg'},
            {id: 'Africa/Nairobi', label: 'Nairobi'},
            {id: 'Africa/Cairo', label: 'Cairo'},
            {id: 'Africa/Dar_es_Salaam', label: 'Dar es Salaam'},
            {id: 'Asia/Jerusalem', label: 'Jerusalem'},
            {id: 'Asia/Amman', label: 'Amman'},
            {id: 'Asia/Beirut', label: 'Beirut'},
            {id: 'Asia/Baghdad', label: 'Baghdad'},
            {id: 'Asia/Riyadh', label: 'Riyadh'},
            {id: 'Asia/Dubai', label: 'Dubai'},
            {id: 'Asia/Doha', label: 'Doha'},
            {id: 'Asia/Kuwait', label: 'Kuwait City'},
            {id: 'Asia/Tehran', label: 'Tehran'},
        ],
    },
    {
        id: 'asia',
        label: 'Asia',
        zones: [
            {id: 'Asia/Karachi', label: 'Karachi'},
            {id: 'Asia/Kolkata', label: 'New Delhi'},
            {id: 'Asia/Kolkata', label: 'Mumbai'},
            {id: 'Asia/Kolkata', label: 'Bangalore'},
            {id: 'Asia/Kolkata', label: 'Kolkata'},
            {id: 'Asia/Dhaka', label: 'Dhaka'},
            {id: 'Asia/Kathmandu', label: 'Kathmandu'},
            {id: 'Asia/Colombo', label: 'Colombo'},
            {id: 'Asia/Bangkok', label: 'Bangkok'},
            {id: 'Asia/Ho_Chi_Minh', label: 'Ho Chi Minh City'},
            {id: 'Asia/Jakarta', label: 'Jakarta'},
            {id: 'Asia/Singapore', label: 'Singapore'},
            {id: 'Asia/Kuala_Lumpur', label: 'Kuala Lumpur'},
            {id: 'Asia/Hong_Kong', label: 'Hong Kong'},
            {id: 'Asia/Shanghai', label: 'Shanghai'},
            {id: 'Asia/Shanghai', label: 'Beijing'},
            {id: 'Asia/Taipei', label: 'Taipei'},
            {id: 'Asia/Seoul', label: 'Seoul'},
            {id: 'Asia/Tokyo', label: 'Tokyo'},
            {id: 'Asia/Manila', label: 'Manila'},
            {id: 'Asia/Ulaanbaatar', label: 'Ulaanbaatar'},
        ],
    },
    {
        id: 'oceania',
        label: 'Oceania',
        zones: [
            {id: 'Australia/Perth', label: 'Perth'},
            {id: 'Australia/Adelaide', label: 'Adelaide'},
            {id: 'Australia/Darwin', label: 'Darwin'},
            {id: 'Australia/Brisbane', label: 'Brisbane'},
            {id: 'Australia/Sydney', label: 'Sydney'},
            {id: 'Australia/Hobart', label: 'Hobart'},
            {id: 'Pacific/Auckland', label: 'Auckland'},
            {id: 'Pacific/Fiji', label: 'Fiji'},
        ],
    },
];

const ZONE_MAP = new Map();
for (const region of TIMEZONE_REGIONS) {
    for (const zone of region.zones) {
        ZONE_MAP.set(zone.id, {
            ...zone,
            regionId: region.id,
            regionLabel: region.label,
        });
    }
}

export function getDefaultZone() {
    return TIMEZONE_REGIONS[0].zones[0];
}

export function getZoneInfo(zoneId) {
    return ZONE_MAP.get(zoneId) ?? null;
}

export function getRegionInfo(regionId) {
    return TIMEZONE_REGIONS.find(region => region.id === regionId) ?? null;
}

export function getRegionIdForZone(zoneId) {
    return getZoneInfo(zoneId)?.regionId ?? TIMEZONE_REGIONS[0].id;
}

export function getDisplayLabelForZone(zoneId) {
    return getZoneInfo(zoneId)?.label ?? zoneId ?? getDefaultZone().label;
}
