// 国家数据 - 完整补全版本
const zhCountries = {
  "CN": "中国",
  "US": "美国",
  "JP": "日本",
  "KR": "韩国",
  "GB": "英国",
  "DE": "德国",
  "FR": "法国",
  "IT": "意大利",
  "ES": "西班牙",
  "RU": "俄罗斯",
  "BR": "巴西",
  "IN": "印度",
  "AU": "澳大利亚",
  "CA": "加拿大",
  "MX": "墨西哥",
  "ID": "印度尼西亚",
  "TH": "泰国",
  "VN": "越南",
  "MY": "马来西亚",
  "SG": "新加坡",
  "PH": "菲律宾",
  "TW": "中国台湾",
  "HK": "中国香港",
  "MO": "中国澳门",
  "AE": "阿联酋",
  "SA": "沙特阿拉伯",
  "TR": "土耳其",
  "EG": "埃及",
  "ZA": "南非",
  "NG": "尼日利亚",
  "AR": "阿根廷",
  "CL": "智利",
  "CO": "哥伦比亚",
  "PE": "秘鲁",
  "PL": "波兰",
  "NL": "荷兰",
  "BE": "比利时",
  "SE": "瑞典",
  "NO": "挪威",
  "DK": "丹麦",
  "FI": "芬兰",
  "AT": "奥地利",
  "CH": "瑞士",
  "PT": "葡萄牙",
  "GR": "希腊",
  "CZ": "捷克",
  "RO": "罗马尼亚",
  "HU": "匈牙利",
  "UA": "乌克兰",
  "IL": "以色列",
  "PK": "巴基斯坦",
  "BD": "孟加拉国",
  "NZ": "新西兰",
  "HR": "克罗地亚",
  "BG": "保加利亚",
  // --- 新增补全 ---
  "KP": "朝鲜",
  "IE": "爱尔兰",
  "AG": "安提瓜和巴布达",
  "BS": "巴哈马",
  "BB": "巴巴多斯",
  "BZ": "伯利兹",
  "BW": "博茨瓦纳",
  "KY": "开曼群岛",
  "CX": "圣诞岛",
  "CC": "科科斯群岛",
  "CK": "库克群岛",
  "DM": "多米尼克",
  "SZ": "埃斯瓦蒂尼",
  "FK": "福克兰群岛",
  "FJ": "斐济",
  "GM": "冈比亚",
  "GH": "加纳",
  "GI": "直布罗陀",
  "GD": "格林纳达",
  "GU": "关岛",
  "GG": "根西岛",
  "GY": "圭亚那",
  "HM": "赫德岛和麦克唐纳群岛",
  "IM": "曼岛",
  "JM": "牙买加",
  "JE": "泽西岛",
  "KE": "肯尼亚",
  "KI": "基里巴斯",
  "LS": "莱索托",
  "LR": "利比里亚",
  "MW": "马拉维",
  "MH": "马绍尔群岛",
  "MU": "毛里求斯",
  "FM": "密克罗尼西亚",
  "MS": "蒙特塞拉特",
  "NA": "纳米比亚",
  "NR": "瑙鲁",
  "NU": "纽埃",
  "NF": "诺福克岛",
  "MP": "北马里亚纳群岛",
  "PW": "帕劳",
  "PG": "巴布亚新几内亚",
  "PN": "皮特凯恩群岛",
  "SH": "圣赫勒拿",
  "KN": "圣基茨和尼维斯",
  "LC": "圣卢西亚",
  "VC": "圣文森特和格林纳丁斯",
  "SL": "塞拉利昂",
  "SB": "所罗门群岛",
  "GS": "南乔治亚岛和南桑威奇群岛",
  "SS": "南苏丹",
  "TK": "托克劳",
  "TT": "特立尼达和多巴哥",
  "TC": "特克斯和凯科斯群岛",
  "TV": "图瓦卢",
  "UG": "乌干达",
  "UM": "美国本土外小岛屿",
  "VG": "英属维尔京群岛",
  "VI": "美属维尔京群岛",
  "ZM": "赞比亚",
  "ZW": "津巴布韦",
  "AS": "美属萨摩亚",
  "AI": "安圭拉",
  "AQ": "南极洲",
  "BM": "百幕大",
  "IO": "英属印度洋领地",
  "BJ": "贝宁",
  "BF": "布基纳法索",
  "BI": "布隆迪",
  "CM": "喀麦隆",
  "CF": "中非共和国",
  "TD": "乍得",
  "CD": "刚果民主共和国",
  "CI": "科特迪瓦",
  "DJ": "吉布提",
  "GF": "法属圭亚那",
  "PF": "法属波利尼西亚",
  "TF": "法属南部领地",
  "GA": "加蓬",
  "GP": "瓜德罗普",
  "GN": "几内亚",
  "HT": "海地",
  "LU": "卢森堡",
  "MG": "马达加斯加",
  "ML": "马里",
  "MQ": "马提尼克",
  "YT": "马约特",
  "MC": "摩纳哥",
  "NC": "新喀里多尼亚",
  "NE": "尼日尔",
  "RE": "留尼汪",
  "BL": "圣巴泰勒米",
  "MF": "法属圣马丁",
  "PM": "圣皮埃尔和密克隆",
  "SN": "塞内加尔",
  "SC": "塞舌尔",
  "TG": "多哥",
  "WF": "瓦利斯和富图纳",
  "LI": "列支敦士登",
  "VA": "梵蒂冈",
  "SM": "圣马力诺",
  "BO": "玻利维亚",
  "CR": "哥斯达黎加",
  "CU": "古巴",
  "DO": "多米尼加共和国",
  "EC": "厄瓜多尔",
  "SV": "萨尔瓦多",
  "GQ": "赤道几内亚",
  "GT": "危地马拉",
  "HN": "洪都拉斯",
  "NI": "尼加拉瓜",
  "PA": "巴拿马",
  "PY": "巴拉圭",
  "PR": "波多黎各",
  "UY": "乌拉圭",
  "VE": "委内瑞拉",
  "CV": "佛得角",
  "GW": "几内亚比绍",
  "MZ": "莫桑比克",
  "ST": "圣多美和普林西比",
  "AO": "安哥拉",
  "BN": "文莱",
  "BH": "巴林",
  "KM": "科摩罗",
  "IQ": "伊拉克",
  "JO": "约旦",
  "KW": "科威特",
  "LB": "黎巴嫩",
  "LY": "利比亚",
  "MR": "毛里塔尼亚",
  "MA": "摩洛哥",
  "OM": "阿曼",
  "PS": "巴勒斯坦",
  "QA": "卡塔尔",
  "SD": "苏丹",
  "SY": "叙利亚",
  "TN": "突尼斯",
  "EH": "西撒哈拉",
  "YE": "也门",
  "DZ": "阿尔及利亚",
  "MM": "缅甸",
  "LK": "斯里兰卡",
  "CW": "库拉索",
  "SX": "荷属圣马丁",
  "SR": "苏里南",
  "BQ": "荷属加勒比区",
  "MD": "摩尔多瓦",
  "LA": "老挝",
  "AL": "阿尔巴尼亚",
  "AD": "安道尔",
  "AM": "亚美尼亚",
  "AZ": "阿塞拜疆",
  "BY": "白俄罗斯",
  "BT": "不丹",
  "BA": "波斯尼亚和黑塞哥维那",
  "KH": "柬埔寨",
  "CY": "塞浦路斯",
  "ER": "厄立特里亚",
  "EE": "爱沙尼亚",
  "ET": "埃塞俄比亚",
  "GE": "格鲁吉亚",
  "GL": "格陵兰",
  "IS": "冰岛",
  "IR": "伊朗",
  "AF": "阿富汗",
  "KZ": "哈萨克斯坦",
  "KG": "吉尔吉斯斯坦",
  "LV": "拉脱维亚",
  "LT": "立陶宛",
  "MV": "马尔代夫",
  "MT": "马耳他",
  "MN": "蒙古",
  "ME": "黑山",
  "RS": "塞尔维亚",
  "NP": "尼泊尔",
  "MK": "北马其顿",
  "SJ": "斯瓦尔巴群岛和扬马延岛",
  "BV": "布韦岛",
  "RW": "卢旺达",
  "WS": "萨摩亚",
  "SK": "斯洛伐克",
  "SI": "斯洛文尼亚",
  "SO": "索马里",
  "TJ": "塔吉克斯坦",
  "TZ": "坦桑尼亚",
  "TL": "东帝汶",
  "TO": "汤加",
  "TM": "土库曼斯坦",
  "UZ": "乌兹别克斯坦",
  "VU": "瓦努阿图"
}

const enCountries = {
  "CN": "China",
  "US": "United States",
  "JP": "Japan",
  "KR": "South Korea",
  "GB": "United Kingdom",
  "DE": "Germany",
  "FR": "France",
  "IT": "Italy",
  "ES": "Spain",
  "RU": "Russia",
  "BR": "Brazil",
  "IN": "India",
  "AU": "Australia",
  "CA": "Canada",
  "MX": "Mexico",
  "ID": "Indonesia",
  "TH": "Thailand",
  "VN": "Vietnam",
  "MY": "Malaysia",
  "SG": "Singapore",
  "PH": "Philippines",
  "TW": "Taiwan",
  "HK": "Hong Kong",
  "MO": "Macao",
  "AE": "UAE",
  "SA": "Saudi Arabia",
  "TR": "Turkey",
  "EG": "Egypt",
  "ZA": "South Africa",
  "NG": "Nigeria",
  "AR": "Argentina",
  "CL": "Chile",
  "CO": "Colombia",
  "PE": "Peru",
  "PL": "Poland",
  "NL": "Netherlands",
  "BE": "Belgium",
  "SE": "Sweden",
  "NO": "Norway",
  "DK": "Denmark",
  "FI": "Finland",
  "AT": "Austria",
  "CH": "Switzerland",
  "PT": "Portugal",
  "GR": "Greece",
  "CZ": "Czech Republic",
  "RO": "Romania",
  "HU": "Hungary",
  "UA": "Ukraine",
  "IL": "Israel",
  "PK": "Pakistan",
  "BD": "Bangladesh",
  "NZ": "New Zealand",
  "HR": "Croatia",
  "BG": "Bulgaria",
  // --- 新增补全 ---
  "KP": "North Korea",
  "IE": "Ireland",
  "AG": "Antigua and Barbuda",
  "BS": "Bahamas",
  "BB": "Barbados",
  "BZ": "Belize",
  "BW": "Botswana",
  "KY": "Cayman Islands",
  "CX": "Christmas Island",
  "CC": "Cocos Islands",
  "CK": "Cook Islands",
  "DM": "Dominica",
  "SZ": "Eswatini",
  "FK": "Falkland Islands",
  "FJ": "Fiji",
  "GM": "Gambia",
  "GH": "Ghana",
  "GI": "Gibraltar",
  "GD": "Grenada",
  "GU": "Guam",
  "GG": "Guernsey",
  "GY": "Guyana",
  "HM": "Heard Island and McDonald Islands",
  "IM": "Isle of Man",
  "JM": "Jamaica",
  "JE": "Jersey",
  "KE": "Kenya",
  "KI": "Kiribati",
  "LS": "Lesotho",
  "LR": "Liberia",
  "MW": "Malawi",
  "MH": "Marshall Islands",
  "MU": "Mauritius",
  "FM": "Micronesia",
  "MS": "Montserrat",
  "NA": "Namibia",
  "NR": "Nauru",
  "NU": "Niue",
  "NF": "Norfolk Island",
  "MP": "Northern Mariana Islands",
  "PW": "Palau",
  "PG": "Papua New Guinea",
  "PN": "Pitcairn Islands",
  "SH": "Saint Helena",
  "KN": "Saint Kitts and Nevis",
  "LC": "Saint Lucia",
  "VC": "Saint Vincent and the Grenadines",
  "SL": "Sierra Leone",
  "SB": "Solomon Islands",
  "GS": "South Georgia and the South Sandwich Islands",
  "SS": "South Sudan",
  "TK": "Tokelau",
  "TT": "Trinidad and Tobago",
  "TC": "Turks and Caicos Islands",
  "TV": "Tuvalu",
  "UG": "Uganda",
  "UM": "U.S. Minor Outlying Islands",
  "VG": "British Virgin Islands",
  "VI": "U.S. Virgin Islands",
  "ZM": "Zambia",
  "ZW": "Zimbabwe",
  "AS": "American Samoa",
  "AI": "Anguilla",
  "AQ": "Antarctica",
  "BM": "Bermuda",
  "IO": "British Indian Ocean Territory",
  "BJ": "Benin",
  "BF": "Burkina Faso",
  "BI": "Burundi",
  "CM": "Cameroon",
  "CF": "Central African Republic",
  "TD": "Chad",
  "CD": "DR Congo",
  "CI": "Ivory Coast",
  "DJ": "Djibouti",
  "GF": "French Guiana",
  "PF": "French Polynesia",
  "TF": "French Southern Territories",
  "GA": "Gabon",
  "GP": "Guadeloupe",
  "GN": "Guinea",
  "HT": "Haiti",
  "LU": "Luxembourg",
  "MG": "Madagascar",
  "ML": "Mali",
  "MQ": "Martinique",
  "YT": "Mayotte",
  "MC": "Monaco",
  "NC": "New Caledonia",
  "NE": "Niger",
  "RE": "Réunion",
  "BL": "Saint Barthélemy",
  "MF": "Saint Martin",
  "PM": "Saint Pierre and Miquelon",
  "SN": "Senegal",
  "SC": "Seychelles",
  "TG": "Togo",
  "WF": "Wallis and Futuna",
  "LI": "Liechtenstein",
  "VA": "Vatican City",
  "SM": "San Marino",
  "BO": "Bolivia",
  "CR": "Costa Rica",
  "CU": "Cuba",
  "DO": "Dominican Republic",
  "EC": "Ecuador",
  "SV": "El Salvador",
  "GQ": "Equatorial Guinea",
  "GT": "Guatemala",
  "HN": "Honduras",
  "NI": "Nicaragua",
  "PA": "Panama",
  "PY": "Paraguay",
  "PR": "Puerto Rico",
  "UY": "Uruguay",
  "VE": "Venezuela",
  "CV": "Cape Verde",
  "GW": "Guinea-Bissau",
  "MZ": "Mozambique",
  "ST": "São Tomé and Príncipe",
  "AO": "Angola",
  "BN": "Brunei",
  "BH": "Bahrain",
  "KM": "Comoros",
  "IQ": "Iraq",
  "JO": "Jordan",
  "KW": "Kuwait",
  "LB": "Lebanon",
  "LY": "Libya",
  "MR": "Mauritania",
  "MA": "Morocco",
  "OM": "Oman",
  "PS": "Palestine",
  "QA": "Qatar",
  "SD": "Sudan",
  "SY": "Syria",
  "TN": "Tunisia",
  "EH": "Western Sahara",
  "YE": "Yemen",
  "DZ": "Algeria",
  "MM": "Myanmar",
  "LK": "Sri Lanka",
  "CW": "Curaçao",
  "SX": "Sint Maarten",
  "SR": "Suriname",
  "BQ": "Caribbean Netherlands",
  "MD": "Moldova",
  "LA": "Laos",
  "AL": "Albania",
  "AD": "Andorra",
  "AM": "Armenia",
  "AZ": "Azerbaijan",
  "BY": "Belarus",
  "BT": "Bhutan",
  "BA": "Bosnia and Herzegovina",
  "KH": "Cambodia",
  "CY": "Cyprus",
  "ER": "Eritrea",
  "EE": "Estonia",
  "ET": "Ethiopia",
  "GE": "Georgia",
  "GL": "Greenland",
  "IS": "Iceland",
  "IR": "Iran",
  "AF": "Afghanistan",
  "KZ": "Kazakhstan",
  "KG": "Kyrgyzstan",
  "LV": "Latvia",
  "LT": "Lithuania",
  "MV": "Maldives",
  "MT": "Malta",
  "MN": "Mongolia",
  "ME": "Montenegro",
  "RS": "Serbia",
  "NP": "Nepal",
  "MK": "North Macedonia",
  "SJ": "Svalbard and Jan Mayen",
  "BV": "Bouvet Island",
  "RW": "Rwanda",
  "WS": "Samoa",
  "SK": "Slovakia",
  "SI": "Slovenia",
  "SO": "Somalia",
  "TJ": "Tajikistan",
  "TZ": "Tanzania",
  "TL": "Timor-Leste",
  "TO": "Tonga",
  "TM": "Turkmenistan",
  "UZ": "Uzbekistan",
  "VU": "Vanuatu"
}

// 创建中文名称到国家代码的映射
const zhNameToCode = {}
Object.entries(zhCountries).forEach(([code, zhName]) => {
  zhNameToCode[zhName] = code
})

// 获取国家名称数组，value 固定为中文名称，label 根据当前语言变化
export function getCountryNamesArray() {
  const currentLanguage = localStorage.getItem('language') || 'ZH'

  return Object.entries(zhCountries).map(([code, zhName]) => ({
    value: zhName,
    label: currentLanguage === 'ZH' ? zhName : enCountries[code]
  }))
}

// 根据中文名称获取当前语言环境的翻译
export function translateCountryName(zhName) {
  const currentLanguage = localStorage.getItem('language') || 'ZH'
  const code = zhNameToCode[zhName]

  if (!code) return zhName

  return currentLanguage === 'ZH' ? zhName : enCountries[code]
}
