// 国家数据 - 简化版本，直接内嵌数据
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": "中国香港",
  "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": "新西兰"
}

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",
  "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"
}

// 创建中文名称到国家代码的映射
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]
}
