<?php
/**
 * Country coordinates and timezone helpers.
 *
 * @package SolarDawn_Sunrise_Sunset_Widget
 */

defined( 'ABSPATH' ) || exit;

/**
 * Return representative coordinates and timezones for country selection.
 *
 * @return array
 */
function solardawn_get_countries() {
	return array(
		'Afghanistan' => array( 'lat' => 33.9391, 'lon' => 67.7100, 'timezone' => 'Asia/Kabul', 'location' => 'Kabul' ),
		'Albania' => array( 'lat' => 41.1533, 'lon' => 20.1683, 'timezone' => 'Europe/Tirane', 'location' => 'Tirana' ),
		'Algeria' => array( 'lat' => 28.0339, 'lon' => 1.6596, 'timezone' => 'Africa/Algiers', 'location' => 'Algiers' ),
		'Andorra' => array( 'lat' => 42.5063, 'lon' => 1.5218, 'timezone' => 'Europe/Andorra', 'location' => 'Andorra la Vella' ),
		'Angola' => array( 'lat' => -11.2027, 'lon' => 17.8739, 'timezone' => 'Africa/Luanda', 'location' => 'Luanda' ),
		'Argentina' => array( 'lat' => -38.4161, 'lon' => -63.6167, 'timezone' => 'America/Argentina/Buenos_Aires', 'location' => 'Buenos Aires' ),
		'Armenia' => array( 'lat' => 40.0691, 'lon' => 45.0382, 'timezone' => 'Asia/Yerevan', 'location' => 'Yerevan' ),
		'Australia' => array( 'lat' => -25.2744, 'lon' => 133.7751, 'timezone' => 'Australia/Sydney', 'location' => 'Sydney' ),
		'Austria' => array( 'lat' => 47.5162, 'lon' => 14.5501, 'timezone' => 'Europe/Vienna', 'location' => 'Vienna' ),
		'Azerbaijan' => array( 'lat' => 40.1431, 'lon' => 47.5769, 'timezone' => 'Asia/Baku', 'location' => 'Baku' ),
		'Bahamas' => array( 'lat' => 25.0343, 'lon' => -77.3963, 'timezone' => 'America/Nassau', 'location' => 'Nassau' ),
		'Bahrain' => array( 'lat' => 26.0667, 'lon' => 50.5577, 'timezone' => 'Asia/Bahrain', 'location' => 'Manama' ),
		'Bangladesh' => array( 'lat' => 23.6850, 'lon' => 90.3563, 'timezone' => 'Asia/Dhaka', 'location' => 'Dhaka' ),
		'Barbados' => array( 'lat' => 13.1939, 'lon' => -59.5432, 'timezone' => 'America/Barbados', 'location' => 'Bridgetown' ),
		'Belarus' => array( 'lat' => 53.7098, 'lon' => 27.9534, 'timezone' => 'Europe/Minsk', 'location' => 'Minsk' ),
		'Belgium' => array( 'lat' => 50.5039, 'lon' => 4.4699, 'timezone' => 'Europe/Brussels', 'location' => 'Brussels' ),
		'Belize' => array( 'lat' => 17.1899, 'lon' => -88.4976, 'timezone' => 'America/Belize', 'location' => 'Belmopan' ),
		'Benin' => array( 'lat' => 9.3077, 'lon' => 2.3158, 'timezone' => 'Africa/Porto-Novo', 'location' => 'Porto-Novo' ),
		'Bhutan' => array( 'lat' => 27.5142, 'lon' => 90.4336, 'timezone' => 'Asia/Thimphu', 'location' => 'Thimphu' ),
		'Bolivia' => array( 'lat' => -16.2902, 'lon' => -63.5887, 'timezone' => 'America/La_Paz', 'location' => 'La Paz' ),
		'Bosnia and Herzegovina' => array( 'lat' => 43.9159, 'lon' => 17.6791, 'timezone' => 'Europe/Sarajevo', 'location' => 'Sarajevo' ),
		'Botswana' => array( 'lat' => -22.3285, 'lon' => 24.6849, 'timezone' => 'Africa/Gaborone', 'location' => 'Gaborone' ),
		'Brazil' => array( 'lat' => -14.2350, 'lon' => -51.9253, 'timezone' => 'America/Sao_Paulo', 'location' => 'Brasilia' ),
		'Brunei' => array( 'lat' => 4.5353, 'lon' => 114.7277, 'timezone' => 'Asia/Brunei', 'location' => 'Bandar Seri Begawan' ),
		'Bulgaria' => array( 'lat' => 42.7339, 'lon' => 25.4858, 'timezone' => 'Europe/Sofia', 'location' => 'Sofia' ),
		'Burkina Faso' => array( 'lat' => 12.2383, 'lon' => -1.5616, 'timezone' => 'Africa/Ouagadougou', 'location' => 'Ouagadougou' ),
		'Burundi' => array( 'lat' => -3.3731, 'lon' => 29.9189, 'timezone' => 'Africa/Bujumbura', 'location' => 'Gitega' ),
		'Cambodia' => array( 'lat' => 12.5657, 'lon' => 104.9910, 'timezone' => 'Asia/Phnom_Penh', 'location' => 'Phnom Penh' ),
		'Cameroon' => array( 'lat' => 7.3697, 'lon' => 12.3547, 'timezone' => 'Africa/Douala', 'location' => 'Yaounde' ),
		'Canada' => array( 'lat' => 56.1304, 'lon' => -106.3468, 'timezone' => 'America/Toronto', 'location' => 'Ottawa' ),
		'Cape Verde' => array( 'lat' => 16.5388, 'lon' => -23.0418, 'timezone' => 'Atlantic/Cape_Verde', 'location' => 'Praia' ),
		'Central African Republic' => array( 'lat' => 6.6111, 'lon' => 20.9394, 'timezone' => 'Africa/Bangui', 'location' => 'Bangui' ),
		'Chad' => array( 'lat' => 15.4542, 'lon' => 18.7322, 'timezone' => 'Africa/Ndjamena', 'location' => 'NDjamena' ),
		'Chile' => array( 'lat' => -35.6751, 'lon' => -71.5430, 'timezone' => 'America/Santiago', 'location' => 'Santiago' ),
		'China' => array( 'lat' => 35.8617, 'lon' => 104.1954, 'timezone' => 'Asia/Shanghai', 'location' => 'Beijing' ),
		'Colombia' => array( 'lat' => 4.5709, 'lon' => -74.2973, 'timezone' => 'America/Bogota', 'location' => 'Bogota' ),
		'Comoros' => array( 'lat' => -11.8750, 'lon' => 43.8722, 'timezone' => 'Indian/Comoro', 'location' => 'Moroni' ),
		'Costa Rica' => array( 'lat' => 9.7489, 'lon' => -83.7534, 'timezone' => 'America/Costa_Rica', 'location' => 'San Jose' ),
		'Croatia' => array( 'lat' => 45.1000, 'lon' => 15.2000, 'timezone' => 'Europe/Zagreb', 'location' => 'Zagreb' ),
		'Cuba' => array( 'lat' => 21.5218, 'lon' => -77.7812, 'timezone' => 'America/Havana', 'location' => 'Havana' ),
		'Cyprus' => array( 'lat' => 35.1264, 'lon' => 33.4299, 'timezone' => 'Asia/Nicosia', 'location' => 'Nicosia' ),
		'Czechia' => array( 'lat' => 49.8175, 'lon' => 15.4730, 'timezone' => 'Europe/Prague', 'location' => 'Prague' ),
		'Denmark' => array( 'lat' => 56.2639, 'lon' => 9.5018, 'timezone' => 'Europe/Copenhagen', 'location' => 'Copenhagen' ),
		'Djibouti' => array( 'lat' => 11.8251, 'lon' => 42.5903, 'timezone' => 'Africa/Djibouti', 'location' => 'Djibouti' ),
		'Dominican Republic' => array( 'lat' => 18.7357, 'lon' => -70.1627, 'timezone' => 'America/Santo_Domingo', 'location' => 'Santo Domingo' ),
		'Ecuador' => array( 'lat' => -1.8312, 'lon' => -78.1834, 'timezone' => 'America/Guayaquil', 'location' => 'Quito' ),
		'Egypt' => array( 'lat' => 26.8206, 'lon' => 30.8025, 'timezone' => 'Africa/Cairo', 'location' => 'Cairo' ),
		'El Salvador' => array( 'lat' => 13.7942, 'lon' => -88.8965, 'timezone' => 'America/El_Salvador', 'location' => 'San Salvador' ),
		'Equatorial Guinea' => array( 'lat' => 1.6508, 'lon' => 10.2679, 'timezone' => 'Africa/Malabo', 'location' => 'Malabo' ),
		'Eritrea' => array( 'lat' => 15.1794, 'lon' => 39.7823, 'timezone' => 'Africa/Asmara', 'location' => 'Asmara' ),
		'Estonia' => array( 'lat' => 58.5953, 'lon' => 25.0136, 'timezone' => 'Europe/Tallinn', 'location' => 'Tallinn' ),
		'Eswatini' => array( 'lat' => -26.5225, 'lon' => 31.4659, 'timezone' => 'Africa/Mbabane', 'location' => 'Mbabane' ),
		'Ethiopia' => array( 'lat' => 9.1450, 'lon' => 40.4897, 'timezone' => 'Africa/Addis_Ababa', 'location' => 'Addis Ababa' ),
		'Fiji' => array( 'lat' => -16.5782, 'lon' => 179.4144, 'timezone' => 'Pacific/Fiji', 'location' => 'Suva' ),
		'Finland' => array( 'lat' => 61.9241, 'lon' => 25.7482, 'timezone' => 'Europe/Helsinki', 'location' => 'Helsinki' ),
		'France' => array( 'lat' => 46.2276, 'lon' => 2.2137, 'timezone' => 'Europe/Paris', 'location' => 'Paris' ),
		'Gabon' => array( 'lat' => -0.8037, 'lon' => 11.6094, 'timezone' => 'Africa/Libreville', 'location' => 'Libreville' ),
		'Gambia' => array( 'lat' => 13.4432, 'lon' => -15.3101, 'timezone' => 'Africa/Banjul', 'location' => 'Banjul' ),
		'Georgia' => array( 'lat' => 42.3154, 'lon' => 43.3569, 'timezone' => 'Asia/Tbilisi', 'location' => 'Tbilisi' ),
		'Germany' => array( 'lat' => 51.1657, 'lon' => 10.4515, 'timezone' => 'Europe/Berlin', 'location' => 'Berlin' ),
		'Ghana' => array( 'lat' => 7.9465, 'lon' => -1.0232, 'timezone' => 'Africa/Accra', 'location' => 'Accra' ),
		'Greece' => array( 'lat' => 39.0742, 'lon' => 21.8243, 'timezone' => 'Europe/Athens', 'location' => 'Athens' ),
		'Guatemala' => array( 'lat' => 15.7835, 'lon' => -90.2308, 'timezone' => 'America/Guatemala', 'location' => 'Guatemala City' ),
		'Guinea' => array( 'lat' => 9.9456, 'lon' => -9.6966, 'timezone' => 'Africa/Conakry', 'location' => 'Conakry' ),
		'Guyana' => array( 'lat' => 4.8604, 'lon' => -58.9302, 'timezone' => 'America/Guyana', 'location' => 'Georgetown' ),
		'Haiti' => array( 'lat' => 18.9712, 'lon' => -72.2852, 'timezone' => 'America/Port-au-Prince', 'location' => 'Port-au-Prince' ),
		'Honduras' => array( 'lat' => 15.2000, 'lon' => -86.2419, 'timezone' => 'America/Tegucigalpa', 'location' => 'Tegucigalpa' ),
		'Hungary' => array( 'lat' => 47.1625, 'lon' => 19.5033, 'timezone' => 'Europe/Budapest', 'location' => 'Budapest' ),
		'Iceland' => array( 'lat' => 64.9631, 'lon' => -19.0208, 'timezone' => 'Atlantic/Reykjavik', 'location' => 'Reykjavik' ),
		'India' => array( 'lat' => 20.5937, 'lon' => 78.9629, 'timezone' => 'Asia/Kolkata', 'location' => 'New Delhi' ),
		'Indonesia' => array( 'lat' => -0.7893, 'lon' => 113.9213, 'timezone' => 'Asia/Jakarta', 'location' => 'Jakarta' ),
		'Iran' => array( 'lat' => 32.4279, 'lon' => 53.6880, 'timezone' => 'Asia/Tehran', 'location' => 'Tehran' ),
		'Iraq' => array( 'lat' => 33.2232, 'lon' => 43.6793, 'timezone' => 'Asia/Baghdad', 'location' => 'Baghdad' ),
		'Ireland' => array( 'lat' => 53.1424, 'lon' => -7.6921, 'timezone' => 'Europe/Dublin', 'location' => 'Dublin' ),
		'Israel' => array( 'lat' => 31.0461, 'lon' => 34.8516, 'timezone' => 'Asia/Jerusalem', 'location' => 'Jerusalem' ),
		'Italy' => array( 'lat' => 41.8719, 'lon' => 12.5674, 'timezone' => 'Europe/Rome', 'location' => 'Rome' ),
		'Jamaica' => array( 'lat' => 18.1096, 'lon' => -77.2975, 'timezone' => 'America/Jamaica', 'location' => 'Kingston' ),
		'Japan' => array( 'lat' => 36.2048, 'lon' => 138.2529, 'timezone' => 'Asia/Tokyo', 'location' => 'Tokyo' ),
		'Jordan' => array( 'lat' => 30.5852, 'lon' => 36.2384, 'timezone' => 'Asia/Amman', 'location' => 'Amman' ),
		'Kazakhstan' => array( 'lat' => 48.0196, 'lon' => 66.9237, 'timezone' => 'Asia/Almaty', 'location' => 'Astana' ),
		'Kenya' => array( 'lat' => -0.0236, 'lon' => 37.9062, 'timezone' => 'Africa/Nairobi', 'location' => 'Nairobi' ),
		'Kuwait' => array( 'lat' => 29.3117, 'lon' => 47.4818, 'timezone' => 'Asia/Kuwait', 'location' => 'Kuwait City' ),
		'Kyrgyzstan' => array( 'lat' => 41.2044, 'lon' => 74.7661, 'timezone' => 'Asia/Bishkek', 'location' => 'Bishkek' ),
		'Laos' => array( 'lat' => 19.8563, 'lon' => 102.4955, 'timezone' => 'Asia/Vientiane', 'location' => 'Vientiane' ),
		'Latvia' => array( 'lat' => 56.8796, 'lon' => 24.6032, 'timezone' => 'Europe/Riga', 'location' => 'Riga' ),
		'Lebanon' => array( 'lat' => 33.8547, 'lon' => 35.8623, 'timezone' => 'Asia/Beirut', 'location' => 'Beirut' ),
		'Lesotho' => array( 'lat' => -29.6100, 'lon' => 28.2336, 'timezone' => 'Africa/Maseru', 'location' => 'Maseru' ),
		'Liberia' => array( 'lat' => 6.4281, 'lon' => -9.4295, 'timezone' => 'Africa/Monrovia', 'location' => 'Monrovia' ),
		'Libya' => array( 'lat' => 26.3351, 'lon' => 17.2283, 'timezone' => 'Africa/Tripoli', 'location' => 'Tripoli' ),
		'Liechtenstein' => array( 'lat' => 47.1660, 'lon' => 9.5554, 'timezone' => 'Europe/Vaduz', 'location' => 'Vaduz' ),
		'Lithuania' => array( 'lat' => 55.1694, 'lon' => 23.8813, 'timezone' => 'Europe/Vilnius', 'location' => 'Vilnius' ),
		'Luxembourg' => array( 'lat' => 49.8153, 'lon' => 6.1296, 'timezone' => 'Europe/Luxembourg', 'location' => 'Luxembourg' ),
		'Madagascar' => array( 'lat' => -18.7669, 'lon' => 46.8691, 'timezone' => 'Indian/Antananarivo', 'location' => 'Antananarivo' ),
		'Malawi' => array( 'lat' => -13.2543, 'lon' => 34.3015, 'timezone' => 'Africa/Blantyre', 'location' => 'Lilongwe' ),
		'Malaysia' => array( 'lat' => 4.2105, 'lon' => 101.9758, 'timezone' => 'Asia/Kuala_Lumpur', 'location' => 'Kuala Lumpur' ),
		'Maldives' => array( 'lat' => 3.2028, 'lon' => 73.2207, 'timezone' => 'Indian/Maldives', 'location' => 'Male' ),
		'Mali' => array( 'lat' => 17.5707, 'lon' => -3.9962, 'timezone' => 'Africa/Bamako', 'location' => 'Bamako' ),
		'Malta' => array( 'lat' => 35.9375, 'lon' => 14.3754, 'timezone' => 'Europe/Malta', 'location' => 'Valletta' ),
		'Mauritania' => array( 'lat' => 21.0079, 'lon' => -10.9408, 'timezone' => 'Africa/Nouakchott', 'location' => 'Nouakchott' ),
		'Mauritius' => array( 'lat' => -20.3484, 'lon' => 57.5522, 'timezone' => 'Indian/Mauritius', 'location' => 'Port Louis' ),
		'Mexico' => array( 'lat' => 23.6345, 'lon' => -102.5528, 'timezone' => 'America/Mexico_City', 'location' => 'Mexico City' ),
		'Moldova' => array( 'lat' => 47.4116, 'lon' => 28.3699, 'timezone' => 'Europe/Chisinau', 'location' => 'Chisinau' ),
		'Monaco' => array( 'lat' => 43.7384, 'lon' => 7.4246, 'timezone' => 'Europe/Monaco', 'location' => 'Monaco' ),
		'Mongolia' => array( 'lat' => 46.8625, 'lon' => 103.8467, 'timezone' => 'Asia/Ulaanbaatar', 'location' => 'Ulaanbaatar' ),
		'Montenegro' => array( 'lat' => 42.7087, 'lon' => 19.3744, 'timezone' => 'Europe/Podgorica', 'location' => 'Podgorica' ),
		'Morocco' => array( 'lat' => 31.7917, 'lon' => -7.0926, 'timezone' => 'Africa/Casablanca', 'location' => 'Rabat' ),
		'Mozambique' => array( 'lat' => -18.6657, 'lon' => 35.5296, 'timezone' => 'Africa/Maputo', 'location' => 'Maputo' ),
		'Myanmar' => array( 'lat' => 21.9162, 'lon' => 95.9560, 'timezone' => 'Asia/Yangon', 'location' => 'Naypyidaw' ),
		'Namibia' => array( 'lat' => -22.9576, 'lon' => 18.4904, 'timezone' => 'Africa/Windhoek', 'location' => 'Windhoek' ),
		'Nepal' => array( 'lat' => 28.3949, 'lon' => 84.1240, 'timezone' => 'Asia/Kathmandu', 'location' => 'Kathmandu' ),
		'Netherlands' => array( 'lat' => 52.1326, 'lon' => 5.2913, 'timezone' => 'Europe/Amsterdam', 'location' => 'Amsterdam' ),
		'New Zealand' => array( 'lat' => -40.9006, 'lon' => 174.8860, 'timezone' => 'Pacific/Auckland', 'location' => 'Wellington' ),
		'Nicaragua' => array( 'lat' => 12.8654, 'lon' => -85.2072, 'timezone' => 'America/Managua', 'location' => 'Managua' ),
		'Niger' => array( 'lat' => 17.6078, 'lon' => 8.0817, 'timezone' => 'Africa/Niamey', 'location' => 'Niamey' ),
		'Nigeria' => array( 'lat' => 9.0820, 'lon' => 8.6753, 'timezone' => 'Africa/Lagos', 'location' => 'Abuja' ),
		'North Macedonia' => array( 'lat' => 41.6086, 'lon' => 21.7453, 'timezone' => 'Europe/Skopje', 'location' => 'Skopje' ),
		'Norway' => array( 'lat' => 60.4720, 'lon' => 8.4689, 'timezone' => 'Europe/Oslo', 'location' => 'Oslo' ),
		'Oman' => array( 'lat' => 21.4735, 'lon' => 55.9754, 'timezone' => 'Asia/Muscat', 'location' => 'Muscat' ),
		'Pakistan' => array( 'lat' => 30.3753, 'lon' => 69.3451, 'timezone' => 'Asia/Karachi', 'location' => 'Islamabad' ),
		'Panama' => array( 'lat' => 8.5380, 'lon' => -80.7821, 'timezone' => 'America/Panama', 'location' => 'Panama City' ),
		'Papua New Guinea' => array( 'lat' => -6.3149, 'lon' => 143.9555, 'timezone' => 'Pacific/Port_Moresby', 'location' => 'Port Moresby' ),
		'Paraguay' => array( 'lat' => -23.4425, 'lon' => -58.4438, 'timezone' => 'America/Asuncion', 'location' => 'Asuncion' ),
		'Peru' => array( 'lat' => -9.1900, 'lon' => -75.0152, 'timezone' => 'America/Lima', 'location' => 'Lima' ),
		'Philippines' => array( 'lat' => 12.8797, 'lon' => 121.7740, 'timezone' => 'Asia/Manila', 'location' => 'Manila' ),
		'Poland' => array( 'lat' => 51.9194, 'lon' => 19.1451, 'timezone' => 'Europe/Warsaw', 'location' => 'Warsaw' ),
		'Portugal' => array( 'lat' => 39.3999, 'lon' => -8.2245, 'timezone' => 'Europe/Lisbon', 'location' => 'Lisbon' ),
		'Qatar' => array( 'lat' => 25.3548, 'lon' => 51.1839, 'timezone' => 'Asia/Qatar', 'location' => 'Doha' ),
		'Romania' => array( 'lat' => 45.9432, 'lon' => 24.9668, 'timezone' => 'Europe/Bucharest', 'location' => 'Bucharest' ),
		'Russia' => array( 'lat' => 61.5240, 'lon' => 105.3188, 'timezone' => 'Europe/Moscow', 'location' => 'Moscow' ),
		'Rwanda' => array( 'lat' => -1.9403, 'lon' => 29.8739, 'timezone' => 'Africa/Kigali', 'location' => 'Kigali' ),
		'Saudi Arabia' => array( 'lat' => 23.8859, 'lon' => 45.0792, 'timezone' => 'Asia/Riyadh', 'location' => 'Riyadh' ),
		'Senegal' => array( 'lat' => 14.4974, 'lon' => -14.4524, 'timezone' => 'Africa/Dakar', 'location' => 'Dakar' ),
		'Serbia' => array( 'lat' => 44.0165, 'lon' => 21.0059, 'timezone' => 'Europe/Belgrade', 'location' => 'Belgrade' ),
		'Seychelles' => array( 'lat' => -4.6796, 'lon' => 55.4920, 'timezone' => 'Indian/Mahe', 'location' => 'Victoria' ),
		'Sierra Leone' => array( 'lat' => 8.4606, 'lon' => -11.7799, 'timezone' => 'Africa/Freetown', 'location' => 'Freetown' ),
		'Singapore' => array( 'lat' => 1.3521, 'lon' => 103.8198, 'timezone' => 'Asia/Singapore', 'location' => 'Singapore' ),
		'Slovakia' => array( 'lat' => 48.6690, 'lon' => 19.6990, 'timezone' => 'Europe/Bratislava', 'location' => 'Bratislava' ),
		'Slovenia' => array( 'lat' => 46.1512, 'lon' => 14.9955, 'timezone' => 'Europe/Ljubljana', 'location' => 'Ljubljana' ),
		'South Africa' => array( 'lat' => -30.5595, 'lon' => 22.9375, 'timezone' => 'Africa/Johannesburg', 'location' => 'Pretoria' ),
		'South Korea' => array( 'lat' => 35.9078, 'lon' => 127.7669, 'timezone' => 'Asia/Seoul', 'location' => 'Seoul' ),
		'Spain' => array( 'lat' => 40.4637, 'lon' => -3.7492, 'timezone' => 'Europe/Madrid', 'location' => 'Madrid' ),
		'Sri Lanka' => array( 'lat' => 7.8731, 'lon' => 80.7718, 'timezone' => 'Asia/Colombo', 'location' => 'Colombo' ),
		'Sudan' => array( 'lat' => 12.8628, 'lon' => 30.2176, 'timezone' => 'Africa/Khartoum', 'location' => 'Khartoum' ),
		'Suriname' => array( 'lat' => 3.9193, 'lon' => -56.0278, 'timezone' => 'America/Paramaribo', 'location' => 'Paramaribo' ),
		'Sweden' => array( 'lat' => 60.1282, 'lon' => 18.6435, 'timezone' => 'Europe/Stockholm', 'location' => 'Stockholm' ),
		'Switzerland' => array( 'lat' => 46.8182, 'lon' => 8.2275, 'timezone' => 'Europe/Zurich', 'location' => 'Bern' ),
		'Taiwan' => array( 'lat' => 23.6978, 'lon' => 120.9605, 'timezone' => 'Asia/Taipei', 'location' => 'Taipei' ),
		'Tajikistan' => array( 'lat' => 38.8610, 'lon' => 71.2761, 'timezone' => 'Asia/Dushanbe', 'location' => 'Dushanbe' ),
		'Tanzania' => array( 'lat' => -6.3690, 'lon' => 34.8888, 'timezone' => 'Africa/Dar_es_Salaam', 'location' => 'Dodoma' ),
		'Thailand' => array( 'lat' => 15.8700, 'lon' => 100.9925, 'timezone' => 'Asia/Bangkok', 'location' => 'Bangkok' ),
		'Togo' => array( 'lat' => 8.6195, 'lon' => 0.8248, 'timezone' => 'Africa/Lome', 'location' => 'Lome' ),
		'Trinidad and Tobago' => array( 'lat' => 10.6918, 'lon' => -61.2225, 'timezone' => 'America/Port_of_Spain', 'location' => 'Port of Spain' ),
		'Tunisia' => array( 'lat' => 33.8869, 'lon' => 9.5375, 'timezone' => 'Africa/Tunis', 'location' => 'Tunis' ),
		'Turkey' => array( 'lat' => 38.9637, 'lon' => 35.2433, 'timezone' => 'Europe/Istanbul', 'location' => 'Ankara' ),
		'Turkmenistan' => array( 'lat' => 38.9697, 'lon' => 59.5563, 'timezone' => 'Asia/Ashgabat', 'location' => 'Ashgabat' ),
		'Uganda' => array( 'lat' => 1.3733, 'lon' => 32.2903, 'timezone' => 'Africa/Kampala', 'location' => 'Kampala' ),
		'Ukraine' => array( 'lat' => 48.3794, 'lon' => 31.1656, 'timezone' => 'Europe/Kyiv', 'location' => 'Kyiv' ),
		'United Arab Emirates' => array( 'lat' => 23.4241, 'lon' => 53.8478, 'timezone' => 'Asia/Dubai', 'location' => 'Abu Dhabi' ),
		'United Kingdom' => array( 'lat' => 55.3781, 'lon' => -3.4360, 'timezone' => 'Europe/London', 'location' => 'London' ),
		'United States' => array( 'lat' => 39.8283, 'lon' => -98.5795, 'timezone' => 'America/Chicago', 'location' => 'Washington DC' ),
		'Uruguay' => array( 'lat' => -32.5228, 'lon' => -55.7658, 'timezone' => 'America/Montevideo', 'location' => 'Montevideo' ),
		'Uzbekistan' => array( 'lat' => 41.3775, 'lon' => 64.5853, 'timezone' => 'Asia/Tashkent', 'location' => 'Tashkent' ),
		'Venezuela' => array( 'lat' => 6.4238, 'lon' => -66.5897, 'timezone' => 'America/Caracas', 'location' => 'Caracas' ),
		'Vietnam' => array( 'lat' => 14.0583, 'lon' => 108.2772, 'timezone' => 'Asia/Ho_Chi_Minh', 'location' => 'Hanoi' ),
		'Yemen' => array( 'lat' => 15.5527, 'lon' => 48.5164, 'timezone' => 'Asia/Aden', 'location' => 'Sanaa' ),
		'Zambia' => array( 'lat' => -13.1339, 'lon' => 27.8493, 'timezone' => 'Africa/Lusaka', 'location' => 'Lusaka' ),
		'Zimbabwe' => array( 'lat' => -19.0154, 'lon' => 29.1549, 'timezone' => 'Africa/Harare', 'location' => 'Harare' ),
	);
}

/**
 * Find a country row by name.
 *
 * @param string $country Country name.
 * @return array
 */
function solardawn_get_country_row( $country ) {
	$countries = solardawn_get_countries();
	$country   = trim( (string) $country );

	if ( isset( $countries[ $country ] ) ) {
		return $countries[ $country ];
	}

	foreach ( $countries as $name => $row ) {
		if ( strtolower( $name ) === strtolower( $country ) ) {
			return $row;
		}
	}

	return $countries['Sri Lanka'];
}

/**
 * Return coordinates for a country. Falls back to Sri Lanka when unknown.
 *
 * @param string $country Country name.
 * @return array
 */
function solardawn_get_country_coordinates( $country ) {
	$location = solardawn_find_location_details( $country );

	if ( ! empty( $location ) ) {
		return array(
			'lat'      => (float) $location['lat'],
			'lon'      => (float) $location['lon'],
			'timezone' => (string) $location['timezone'],
		);
	}

	$row = solardawn_get_country_row( $country );

	return array(
		'lat'      => (float) $row['lat'],
		'lon'      => (float) $row['lon'],
		'timezone' => (string) $row['timezone'],
	);
}

/**
 * Return a friendly display location for a country.
 *
 * @param string $country Country name.
 * @return string
 */
function solardawn_get_country_location_name( $country ) {
	$row = solardawn_get_country_row( $country );

	if ( ! empty( $row['location'] ) ) {
		return (string) $row['location'];
	}

	return 'Sri Lanka' === $country ? 'Colombo' : (string) $country;
}

/**
 * Return the compact location data directory.
 *
 * @return string
 */
function solardawn_get_location_data_dir() {
	return trailingslashit( SOLARDAWN_SUN_WIDGET_PATH . 'assets/data' );
}

/**
 * Load JSON from a plugin data file.
 *
 * @param string $path Absolute file path.
 * @return array
 */
function solardawn_load_location_json_file( $path ) {
	if ( ! file_exists( $path ) || ! is_readable( $path ) ) {
		return array();
	}

	$contents = file_get_contents( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
	if ( false === $contents || '' === $contents ) {
		return array();
	}

	$data = json_decode( $contents, true );

	return is_array( $data ) ? $data : array();
}

/**
 * Get compact country list generated from the bundled countries.json data.
 *
 * @return array
 */
function solardawn_get_location_countries() {
	static $countries = null;

	if ( null !== $countries ) {
		return $countries;
	}

	$countries = solardawn_load_location_json_file( solardawn_get_location_data_dir() . 'countries.json' );

	if ( empty( $countries ) ) {
		$countries = array();

		foreach ( solardawn_get_countries() as $name => $row ) {
			$countries[] = array(
				'key'        => solardawn_location_slug( $name ),
				'name'       => $name,
				'capital'    => isset( $row['location'] ) ? $row['location'] : $name,
				'lat'        => $row['lat'],
				'lon'        => $row['lon'],
				'timezone'   => $row['timezone'],
				'stateCount' => 0,
			);
		}
	}

	foreach ( $countries as $index => $country ) {
		if ( empty( $country['name'] ) ) {
			continue;
		}

		$legacy = solardawn_get_legacy_country_row_if_exists( $country['name'] );

		if ( ! empty( $legacy ) ) {
			$countries[ $index ]['lat']      = $legacy['lat'];
			$countries[ $index ]['lon']      = $legacy['lon'];
			$countries[ $index ]['timezone'] = $legacy['timezone'];
			$countries[ $index ]['capital']  = ! empty( $legacy['location'] ) ? $legacy['location'] : $countries[ $index ]['capital'];
		}
	}

	return $countries;
}

/**
 * Get a country row from the legacy representative list without fallback.
 *
 * @param string $country Country name.
 * @return array|null
 */
function solardawn_get_legacy_country_row_if_exists( $country ) {
	$countries = solardawn_get_countries();
	$country   = trim( (string) $country );

	if ( isset( $countries[ $country ] ) ) {
		return $countries[ $country ];
	}

	foreach ( $countries as $name => $row ) {
		if ( strtolower( $name ) === strtolower( $country ) ) {
			return $row;
		}
	}

	return null;
}

/**
 * Create the location data slug used for generated country files.
 *
 * @param string $value Location name.
 * @return string
 */
function solardawn_location_slug( $value ) {
	$value = remove_accents( (string) $value );
	$value = strtolower( $value );
	$value = preg_replace( '/[^a-z0-9]+/', '-', $value );
	$value = trim( (string) $value, '-' );

	return '' !== $value ? $value : 'location';
}

/**
 * Find a country record from the compact country index.
 *
 * @param string $country Country name.
 * @return array
 */
function solardawn_get_location_country_record( $country ) {
	$country = trim( (string) $country );

	foreach ( solardawn_get_location_countries() as $record ) {
		if ( isset( $record['name'] ) && strtolower( $record['name'] ) === strtolower( $country ) ) {
			return $record;
		}
	}

	$legacy = solardawn_get_legacy_country_row_if_exists( $country );

	if ( ! empty( $legacy ) ) {
		return array(
			'key'        => solardawn_location_slug( $country ),
			'name'       => $country,
			'capital'    => ! empty( $legacy['location'] ) ? $legacy['location'] : $country,
			'lat'        => $legacy['lat'],
			'lon'        => $legacy['lon'],
			'timezone'   => $legacy['timezone'],
			'stateCount' => 0,
		);
	}

	foreach ( solardawn_get_location_countries() as $record ) {
		if ( isset( $record['name'] ) && 'Sri Lanka' === $record['name'] ) {
			return $record;
		}
	}

	return array(
		'key'      => 'sri-lanka',
		'name'     => 'Sri Lanka',
		'capital'  => 'Colombo',
		'lat'      => 7.8731,
		'lon'      => 80.7718,
		'timezone' => 'Asia/Colombo',
	);
}

/**
 * Load a compact country detail file.
 *
 * @param string $country Country name.
 * @return array
 */
function solardawn_get_location_country_data( $country ) {
	$record = solardawn_get_location_country_record( $country );
	$key    = ! empty( $record['key'] ) ? sanitize_file_name( $record['key'] ) : solardawn_location_slug( $record['name'] );
	$data   = solardawn_load_location_json_file( solardawn_get_location_data_dir() . 'countries/' . $key . '.json' );

	if ( empty( $data ) ) {
		$data = $record;
	}

	$legacy = solardawn_get_legacy_country_row_if_exists( $record['name'] );

	if ( ! empty( $legacy ) ) {
		$data['lat']      = $legacy['lat'];
		$data['lon']      = $legacy['lon'];
		$data['timezone'] = $legacy['timezone'];
		$data['capital']  = ! empty( $legacy['location'] ) ? $legacy['location'] : ( isset( $data['capital'] ) ? $data['capital'] : $record['name'] );
	}

	return $data;
}

/**
 * Match location names case-insensitively.
 *
 * @param string $left  First name.
 * @param string $right Second name.
 * @return bool
 */
function solardawn_location_names_match( $left, $right ) {
	return strtolower( trim( (string) $left ) ) === strtolower( trim( (string) $right ) );
}

/**
 * Resolve a country/state/city to coordinates and timezone.
 *
 * @param string $country Country name.
 * @param string $state   State name.
 * @param string $city    City name.
 * @return array
 */
function solardawn_find_location_details( $country = 'Sri Lanka', $state = '', $city = '' ) {
	$data        = solardawn_get_location_country_data( $country );
	$country     = isset( $data['name'] ) ? (string) $data['name'] : 'Sri Lanka';
	$state       = trim( (string) $state );
	$city        = trim( (string) $city );
	$location    = array(
		'country'       => $country,
		'state'         => '',
		'city'          => '',
		'location_name' => ! empty( $data['capital'] ) ? (string) $data['capital'] : $country,
		'lat'           => isset( $data['lat'] ) ? (float) $data['lat'] : 7.8731,
		'lon'           => isset( $data['lon'] ) ? (float) $data['lon'] : 80.7718,
		'timezone'      => ! empty( $data['timezone'] ) ? (string) $data['timezone'] : 'Asia/Colombo',
	);
	$matched     = null;
	$state_rows  = isset( $data['states'] ) && is_array( $data['states'] ) ? $data['states'] : array();

	if ( '' !== $state ) {
		foreach ( $state_rows as $row ) {
			if ( isset( $row['name'] ) && solardawn_location_names_match( $row['name'], $state ) ) {
				$matched = $row;
				break;
			}
		}
	}

	if ( is_array( $matched ) ) {
		$location['state']         = (string) $matched['name'];
		$location['location_name'] = (string) $matched['name'];
		$location['lat']           = isset( $matched['lat'] ) ? (float) $matched['lat'] : $location['lat'];
		$location['lon']           = isset( $matched['lon'] ) ? (float) $matched['lon'] : $location['lon'];
		$location['timezone']      = ! empty( $matched['timezone'] ) ? (string) $matched['timezone'] : $location['timezone'];
	}

	if ( '' !== $city ) {
		$search_states = is_array( $matched ) ? array( $matched ) : $state_rows;

		foreach ( $search_states as $state_row ) {
			$cities = isset( $state_row['cities'] ) && is_array( $state_row['cities'] ) ? $state_row['cities'] : array();

			foreach ( $cities as $city_row ) {
				if ( isset( $city_row['name'] ) && solardawn_location_names_match( $city_row['name'], $city ) ) {
					$location['state']         = isset( $state_row['name'] ) ? (string) $state_row['name'] : $location['state'];
					$location['city']          = (string) $city_row['name'];
					$location['location_name'] = (string) $city_row['name'];
					$location['lat']           = isset( $city_row['lat'] ) ? (float) $city_row['lat'] : $location['lat'];
					$location['lon']           = isset( $city_row['lon'] ) ? (float) $city_row['lon'] : $location['lon'];
					$location['timezone']      = ! empty( $city_row['timezone'] ) ? (string) $city_row['timezone'] : $location['timezone'];

					return $location;
				}
			}
		}
	}

	return $location;
}

/**
 * Return state dropdown options for a country.
 *
 * @param string $country Country name.
 * @return array
 */
function solardawn_get_location_states( $country ) {
	$data   = solardawn_get_location_country_data( $country );
	$states = isset( $data['states'] ) && is_array( $data['states'] ) ? $data['states'] : array();

	return array_map(
		function ( $state ) {
			return array(
				'name'      => isset( $state['name'] ) ? (string) $state['name'] : '',
				'lat'       => isset( $state['lat'] ) ? (float) $state['lat'] : '',
				'lon'       => isset( $state['lon'] ) ? (float) $state['lon'] : '',
				'timezone'  => ! empty( $state['timezone'] ) ? (string) $state['timezone'] : '',
				'cityCount' => isset( $state['cities'] ) && is_array( $state['cities'] ) ? count( $state['cities'] ) : 0,
			);
		},
		$states
	);
}

/**
 * Return city dropdown options for a country and state.
 *
 * @param string $country Country name.
 * @param string $state   State name.
 * @return array
 */
function solardawn_get_location_cities( $country, $state ) {
	$data = solardawn_get_location_country_data( $country );

	if ( empty( $data['states'] ) || ! is_array( $data['states'] ) ) {
		return array();
	}

	foreach ( $data['states'] as $state_row ) {
		if ( empty( $state_row['name'] ) || ! solardawn_location_names_match( $state_row['name'], $state ) ) {
			continue;
		}

		$cities = isset( $state_row['cities'] ) && is_array( $state_row['cities'] ) ? $state_row['cities'] : array();

		return array_map(
			function ( $city ) use ( $state_row ) {
				return array(
					'name'     => isset( $city['name'] ) ? (string) $city['name'] : '',
					'lat'      => isset( $city['lat'] ) ? (float) $city['lat'] : '',
					'lon'      => isset( $city['lon'] ) ? (float) $city['lon'] : '',
					'timezone' => ! empty( $city['timezone'] ) ? (string) $city['timezone'] : ( ! empty( $state_row['timezone'] ) ? (string) $state_row['timezone'] : '' ),
				);
			},
			$cities
		);
	}

	return array();
}
