import enCountries from '@/i18n/en/country.json';
import zhCountries from '@/i18n/zh/country.json';

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