/**
 * 国家/地区数据
 * 包含 ISO 3166-1 标准的国家代码、名称、手机区号、国旗 emoji
 */

export interface CountryData {
  /** ISO 3166-1 alpha-2 国家代码 */
  code: string;
  /** 英文名称 */
  nameEn: string;
  /** 中文名称 */
  nameZh: string;
  /** 手机区号 (不含 +) */
  phoneCode: string;
  /** 国旗 emoji */
  flag: string;
  /** 是否常用 (用于排序优先显示) */
  popular?: boolean;
}

/**
 * 完整的国家/地区列表
 * 按字母顺序排列，常用国家标记 popular: true
 */
export const COUNTRIES: CountryData[] = [
  // 常用国家/地区 (优先显示)
  { code: 'CN', nameEn: 'China', nameZh: '中国', phoneCode: '86', flag: '🇨🇳', popular: true },
  { code: 'HK', nameEn: 'Hong Kong', nameZh: '中国香港', phoneCode: '852', flag: '🇭🇰', popular: true },
  { code: 'TW', nameEn: 'Taiwan', nameZh: '中国台湾', phoneCode: '886', flag: '🇹🇼', popular: true },
  { code: 'MO', nameEn: 'Macao', nameZh: '中国澳门', phoneCode: '853', flag: '🇲🇴', popular: true },
  { code: 'US', nameEn: 'United States', nameZh: '美国', phoneCode: '1', flag: '🇺🇸', popular: true },
  { code: 'GB', nameEn: 'United Kingdom', nameZh: '英国', phoneCode: '44', flag: '🇬🇧', popular: true },
  { code: 'JP', nameEn: 'Japan', nameZh: '日本', phoneCode: '81', flag: '🇯🇵', popular: true },
  { code: 'KR', nameEn: 'South Korea', nameZh: '韩国', phoneCode: '82', flag: '🇰🇷', popular: true },
  { code: 'SG', nameEn: 'Singapore', nameZh: '新加坡', phoneCode: '65', flag: '🇸🇬', popular: true },
  { code: 'AU', nameEn: 'Australia', nameZh: '澳大利亚', phoneCode: '61', flag: '🇦🇺', popular: true },
  { code: 'CA', nameEn: 'Canada', nameZh: '加拿大', phoneCode: '1', flag: '🇨🇦', popular: true },
  { code: 'DE', nameEn: 'Germany', nameZh: '德国', phoneCode: '49', flag: '🇩🇪', popular: true },
  { code: 'FR', nameEn: 'France', nameZh: '法国', phoneCode: '33', flag: '🇫🇷', popular: true },
  { code: 'MY', nameEn: 'Malaysia', nameZh: '马来西亚', phoneCode: '60', flag: '🇲🇾', popular: true },
  { code: 'TH', nameEn: 'Thailand', nameZh: '泰国', phoneCode: '66', flag: '🇹🇭', popular: true },
  { code: 'VN', nameEn: 'Vietnam', nameZh: '越南', phoneCode: '84', flag: '🇻🇳', popular: true },
  { code: 'PH', nameEn: 'Philippines', nameZh: '菲律宾', phoneCode: '63', flag: '🇵🇭', popular: true },
  { code: 'ID', nameEn: 'Indonesia', nameZh: '印度尼西亚', phoneCode: '62', flag: '🇮🇩', popular: true },
  { code: 'IN', nameEn: 'India', nameZh: '印度', phoneCode: '91', flag: '🇮🇳', popular: true },
  { code: 'AE', nameEn: 'United Arab Emirates', nameZh: '阿联酋', phoneCode: '971', flag: '🇦🇪', popular: true },

  // 亚洲
  { code: 'AF', nameEn: 'Afghanistan', nameZh: '阿富汗', phoneCode: '93', flag: '🇦🇫' },
  { code: 'AM', nameEn: 'Armenia', nameZh: '亚美尼亚', phoneCode: '374', flag: '🇦🇲' },
  { code: 'AZ', nameEn: 'Azerbaijan', nameZh: '阿塞拜疆', phoneCode: '994', flag: '🇦🇿' },
  { code: 'BH', nameEn: 'Bahrain', nameZh: '巴林', phoneCode: '973', flag: '🇧🇭' },
  { code: 'BD', nameEn: 'Bangladesh', nameZh: '孟加拉国', phoneCode: '880', flag: '🇧🇩' },
  { code: 'BT', nameEn: 'Bhutan', nameZh: '不丹', phoneCode: '975', flag: '🇧🇹' },
  { code: 'BN', nameEn: 'Brunei', nameZh: '文莱', phoneCode: '673', flag: '🇧🇳' },
  { code: 'KH', nameEn: 'Cambodia', nameZh: '柬埔寨', phoneCode: '855', flag: '🇰🇭' },
  { code: 'GE', nameEn: 'Georgia', nameZh: '格鲁吉亚', phoneCode: '995', flag: '🇬🇪' },
  { code: 'IQ', nameEn: 'Iraq', nameZh: '伊拉克', phoneCode: '964', flag: '🇮🇶' },
  { code: 'IR', nameEn: 'Iran', nameZh: '伊朗', phoneCode: '98', flag: '🇮🇷' },
  { code: 'IL', nameEn: 'Israel', nameZh: '以色列', phoneCode: '972', flag: '🇮🇱' },
  { code: 'JO', nameEn: 'Jordan', nameZh: '约旦', phoneCode: '962', flag: '🇯🇴' },
  { code: 'KZ', nameEn: 'Kazakhstan', nameZh: '哈萨克斯坦', phoneCode: '7', flag: '🇰🇿' },
  { code: 'KW', nameEn: 'Kuwait', nameZh: '科威特', phoneCode: '965', flag: '🇰🇼' },
  { code: 'KG', nameEn: 'Kyrgyzstan', nameZh: '吉尔吉斯斯坦', phoneCode: '996', flag: '🇰🇬' },
  { code: 'LA', nameEn: 'Laos', nameZh: '老挝', phoneCode: '856', flag: '🇱🇦' },
  { code: 'LB', nameEn: 'Lebanon', nameZh: '黎巴嫩', phoneCode: '961', flag: '🇱🇧' },
  { code: 'MV', nameEn: 'Maldives', nameZh: '马尔代夫', phoneCode: '960', flag: '🇲🇻' },
  { code: 'MN', nameEn: 'Mongolia', nameZh: '蒙古', phoneCode: '976', flag: '🇲🇳' },
  { code: 'MM', nameEn: 'Myanmar', nameZh: '缅甸', phoneCode: '95', flag: '🇲🇲' },
  { code: 'NP', nameEn: 'Nepal', nameZh: '尼泊尔', phoneCode: '977', flag: '🇳🇵' },
  { code: 'KP', nameEn: 'North Korea', nameZh: '朝鲜', phoneCode: '850', flag: '🇰🇵' },
  { code: 'OM', nameEn: 'Oman', nameZh: '阿曼', phoneCode: '968', flag: '🇴🇲' },
  { code: 'PK', nameEn: 'Pakistan', nameZh: '巴基斯坦', phoneCode: '92', flag: '🇵🇰' },
  { code: 'PS', nameEn: 'Palestine', nameZh: '巴勒斯坦', phoneCode: '970', flag: '🇵🇸' },
  { code: 'QA', nameEn: 'Qatar', nameZh: '卡塔尔', phoneCode: '974', flag: '🇶🇦' },
  { code: 'SA', nameEn: 'Saudi Arabia', nameZh: '沙特阿拉伯', phoneCode: '966', flag: '🇸🇦' },
  { code: 'LK', nameEn: 'Sri Lanka', nameZh: '斯里兰卡', phoneCode: '94', flag: '🇱🇰' },
  { code: 'SY', nameEn: 'Syria', nameZh: '叙利亚', phoneCode: '963', flag: '🇸🇾' },
  { code: 'TJ', nameEn: 'Tajikistan', nameZh: '塔吉克斯坦', phoneCode: '992', flag: '🇹🇯' },
  { code: 'TL', nameEn: 'Timor-Leste', nameZh: '东帝汶', phoneCode: '670', flag: '🇹🇱' },
  { code: 'TR', nameEn: 'Turkey', nameZh: '土耳其', phoneCode: '90', flag: '🇹🇷' },
  { code: 'TM', nameEn: 'Turkmenistan', nameZh: '土库曼斯坦', phoneCode: '993', flag: '🇹🇲' },
  { code: 'UZ', nameEn: 'Uzbekistan', nameZh: '乌兹别克斯坦', phoneCode: '998', flag: '🇺🇿' },
  { code: 'YE', nameEn: 'Yemen', nameZh: '也门', phoneCode: '967', flag: '🇾🇪' },

  // 欧洲
  { code: 'AL', nameEn: 'Albania', nameZh: '阿尔巴尼亚', phoneCode: '355', flag: '🇦🇱' },
  { code: 'AD', nameEn: 'Andorra', nameZh: '安道尔', phoneCode: '376', flag: '🇦🇩' },
  { code: 'AT', nameEn: 'Austria', nameZh: '奥地利', phoneCode: '43', flag: '🇦🇹' },
  { code: 'BY', nameEn: 'Belarus', nameZh: '白俄罗斯', phoneCode: '375', flag: '🇧🇾' },
  { code: 'BE', nameEn: 'Belgium', nameZh: '比利时', phoneCode: '32', flag: '🇧🇪' },
  { code: 'BA', nameEn: 'Bosnia and Herzegovina', nameZh: '波黑', phoneCode: '387', flag: '🇧🇦' },
  { code: 'BG', nameEn: 'Bulgaria', nameZh: '保加利亚', phoneCode: '359', flag: '🇧🇬' },
  { code: 'HR', nameEn: 'Croatia', nameZh: '克罗地亚', phoneCode: '385', flag: '🇭🇷' },
  { code: 'CY', nameEn: 'Cyprus', nameZh: '塞浦路斯', phoneCode: '357', flag: '🇨🇾' },
  { code: 'CZ', nameEn: 'Czech Republic', nameZh: '捷克', phoneCode: '420', flag: '🇨🇿' },
  { code: 'DK', nameEn: 'Denmark', nameZh: '丹麦', phoneCode: '45', flag: '🇩🇰' },
  { code: 'EE', nameEn: 'Estonia', nameZh: '爱沙尼亚', phoneCode: '372', flag: '🇪🇪' },
  { code: 'FI', nameEn: 'Finland', nameZh: '芬兰', phoneCode: '358', flag: '🇫🇮' },
  { code: 'GR', nameEn: 'Greece', nameZh: '希腊', phoneCode: '30', flag: '🇬🇷' },
  { code: 'HU', nameEn: 'Hungary', nameZh: '匈牙利', phoneCode: '36', flag: '🇭🇺' },
  { code: 'IS', nameEn: 'Iceland', nameZh: '冰岛', phoneCode: '354', flag: '🇮🇸' },
  { code: 'IE', nameEn: 'Ireland', nameZh: '爱尔兰', phoneCode: '353', flag: '🇮🇪' },
  { code: 'IT', nameEn: 'Italy', nameZh: '意大利', phoneCode: '39', flag: '🇮🇹' },
  { code: 'XK', nameEn: 'Kosovo', nameZh: '科索沃', phoneCode: '383', flag: '🇽🇰' },
  { code: 'LV', nameEn: 'Latvia', nameZh: '拉脱维亚', phoneCode: '371', flag: '🇱🇻' },
  { code: 'LI', nameEn: 'Liechtenstein', nameZh: '列支敦士登', phoneCode: '423', flag: '🇱🇮' },
  { code: 'LT', nameEn: 'Lithuania', nameZh: '立陶宛', phoneCode: '370', flag: '🇱🇹' },
  { code: 'LU', nameEn: 'Luxembourg', nameZh: '卢森堡', phoneCode: '352', flag: '🇱🇺' },
  { code: 'MT', nameEn: 'Malta', nameZh: '马耳他', phoneCode: '356', flag: '🇲🇹' },
  { code: 'MD', nameEn: 'Moldova', nameZh: '摩尔多瓦', phoneCode: '373', flag: '🇲🇩' },
  { code: 'MC', nameEn: 'Monaco', nameZh: '摩纳哥', phoneCode: '377', flag: '🇲🇨' },
  { code: 'ME', nameEn: 'Montenegro', nameZh: '黑山', phoneCode: '382', flag: '🇲🇪' },
  { code: 'NL', nameEn: 'Netherlands', nameZh: '荷兰', phoneCode: '31', flag: '🇳🇱' },
  { code: 'MK', nameEn: 'North Macedonia', nameZh: '北马其顿', phoneCode: '389', flag: '🇲🇰' },
  { code: 'NO', nameEn: 'Norway', nameZh: '挪威', phoneCode: '47', flag: '🇳🇴' },
  { code: 'PL', nameEn: 'Poland', nameZh: '波兰', phoneCode: '48', flag: '🇵🇱' },
  { code: 'PT', nameEn: 'Portugal', nameZh: '葡萄牙', phoneCode: '351', flag: '🇵🇹' },
  { code: 'RO', nameEn: 'Romania', nameZh: '罗马尼亚', phoneCode: '40', flag: '🇷🇴' },
  { code: 'RU', nameEn: 'Russia', nameZh: '俄罗斯', phoneCode: '7', flag: '🇷🇺' },
  { code: 'SM', nameEn: 'San Marino', nameZh: '圣马力诺', phoneCode: '378', flag: '🇸🇲' },
  { code: 'RS', nameEn: 'Serbia', nameZh: '塞尔维亚', phoneCode: '381', flag: '🇷🇸' },
  { code: 'SK', nameEn: 'Slovakia', nameZh: '斯洛伐克', phoneCode: '421', flag: '🇸🇰' },
  { code: 'SI', nameEn: 'Slovenia', nameZh: '斯洛文尼亚', phoneCode: '386', flag: '🇸🇮' },
  { code: 'ES', nameEn: 'Spain', nameZh: '西班牙', phoneCode: '34', flag: '🇪🇸' },
  { code: 'SE', nameEn: 'Sweden', nameZh: '瑞典', phoneCode: '46', flag: '🇸🇪' },
  { code: 'CH', nameEn: 'Switzerland', nameZh: '瑞士', phoneCode: '41', flag: '🇨🇭' },
  { code: 'UA', nameEn: 'Ukraine', nameZh: '乌克兰', phoneCode: '380', flag: '🇺🇦' },
  { code: 'VA', nameEn: 'Vatican City', nameZh: '梵蒂冈', phoneCode: '39', flag: '🇻🇦' },

  // 非洲
  { code: 'DZ', nameEn: 'Algeria', nameZh: '阿尔及利亚', phoneCode: '213', flag: '🇩🇿' },
  { code: 'AO', nameEn: 'Angola', nameZh: '安哥拉', phoneCode: '244', flag: '🇦🇴' },
  { code: 'BJ', nameEn: 'Benin', nameZh: '贝宁', phoneCode: '229', flag: '🇧🇯' },
  { code: 'BW', nameEn: 'Botswana', nameZh: '博茨瓦纳', phoneCode: '267', flag: '🇧🇼' },
  { code: 'BF', nameEn: 'Burkina Faso', nameZh: '布基纳法索', phoneCode: '226', flag: '🇧🇫' },
  { code: 'BI', nameEn: 'Burundi', nameZh: '布隆迪', phoneCode: '257', flag: '🇧🇮' },
  { code: 'CV', nameEn: 'Cabo Verde', nameZh: '佛得角', phoneCode: '238', flag: '🇨🇻' },
  { code: 'CM', nameEn: 'Cameroon', nameZh: '喀麦隆', phoneCode: '237', flag: '🇨🇲' },
  { code: 'CF', nameEn: 'Central African Republic', nameZh: '中非', phoneCode: '236', flag: '🇨🇫' },
  { code: 'TD', nameEn: 'Chad', nameZh: '乍得', phoneCode: '235', flag: '🇹🇩' },
  { code: 'KM', nameEn: 'Comoros', nameZh: '科摩罗', phoneCode: '269', flag: '🇰🇲' },
  { code: 'CG', nameEn: 'Congo', nameZh: '刚果(布)', phoneCode: '242', flag: '🇨🇬' },
  { code: 'CD', nameEn: 'Congo (DRC)', nameZh: '刚果(金)', phoneCode: '243', flag: '🇨🇩' },
  { code: 'CI', nameEn: "Côte d'Ivoire", nameZh: '科特迪瓦', phoneCode: '225', flag: '🇨🇮' },
  { code: 'DJ', nameEn: 'Djibouti', nameZh: '吉布提', phoneCode: '253', flag: '🇩🇯' },
  { code: 'EG', nameEn: 'Egypt', nameZh: '埃及', phoneCode: '20', flag: '🇪🇬' },
  { code: 'GQ', nameEn: 'Equatorial Guinea', nameZh: '赤道几内亚', phoneCode: '240', flag: '🇬🇶' },
  { code: 'ER', nameEn: 'Eritrea', nameZh: '厄立特里亚', phoneCode: '291', flag: '🇪🇷' },
  { code: 'SZ', nameEn: 'Eswatini', nameZh: '斯威士兰', phoneCode: '268', flag: '🇸🇿' },
  { code: 'ET', nameEn: 'Ethiopia', nameZh: '埃塞俄比亚', phoneCode: '251', flag: '🇪🇹' },
  { code: 'GA', nameEn: 'Gabon', nameZh: '加蓬', phoneCode: '241', flag: '🇬🇦' },
  { code: 'GM', nameEn: 'Gambia', nameZh: '冈比亚', phoneCode: '220', flag: '🇬🇲' },
  { code: 'GH', nameEn: 'Ghana', nameZh: '加纳', phoneCode: '233', flag: '🇬🇭' },
  { code: 'GN', nameEn: 'Guinea', nameZh: '几内亚', phoneCode: '224', flag: '🇬🇳' },
  { code: 'GW', nameEn: 'Guinea-Bissau', nameZh: '几内亚比绍', phoneCode: '245', flag: '🇬🇼' },
  { code: 'KE', nameEn: 'Kenya', nameZh: '肯尼亚', phoneCode: '254', flag: '🇰🇪' },
  { code: 'LS', nameEn: 'Lesotho', nameZh: '莱索托', phoneCode: '266', flag: '🇱🇸' },
  { code: 'LR', nameEn: 'Liberia', nameZh: '利比里亚', phoneCode: '231', flag: '🇱🇷' },
  { code: 'LY', nameEn: 'Libya', nameZh: '利比亚', phoneCode: '218', flag: '🇱🇾' },
  { code: 'MG', nameEn: 'Madagascar', nameZh: '马达加斯加', phoneCode: '261', flag: '🇲🇬' },
  { code: 'MW', nameEn: 'Malawi', nameZh: '马拉维', phoneCode: '265', flag: '🇲🇼' },
  { code: 'ML', nameEn: 'Mali', nameZh: '马里', phoneCode: '223', flag: '🇲🇱' },
  { code: 'MR', nameEn: 'Mauritania', nameZh: '毛里塔尼亚', phoneCode: '222', flag: '🇲🇷' },
  { code: 'MU', nameEn: 'Mauritius', nameZh: '毛里求斯', phoneCode: '230', flag: '🇲🇺' },
  { code: 'MA', nameEn: 'Morocco', nameZh: '摩洛哥', phoneCode: '212', flag: '🇲🇦' },
  { code: 'MZ', nameEn: 'Mozambique', nameZh: '莫桑比克', phoneCode: '258', flag: '🇲🇿' },
  { code: 'NA', nameEn: 'Namibia', nameZh: '纳米比亚', phoneCode: '264', flag: '🇳🇦' },
  { code: 'NE', nameEn: 'Niger', nameZh: '尼日尔', phoneCode: '227', flag: '🇳🇪' },
  { code: 'NG', nameEn: 'Nigeria', nameZh: '尼日利亚', phoneCode: '234', flag: '🇳🇬' },
  { code: 'RW', nameEn: 'Rwanda', nameZh: '卢旺达', phoneCode: '250', flag: '🇷🇼' },
  { code: 'ST', nameEn: 'São Tomé and Príncipe', nameZh: '圣多美和普林西比', phoneCode: '239', flag: '🇸🇹' },
  { code: 'SN', nameEn: 'Senegal', nameZh: '塞内加尔', phoneCode: '221', flag: '🇸🇳' },
  { code: 'SC', nameEn: 'Seychelles', nameZh: '塞舌尔', phoneCode: '248', flag: '🇸🇨' },
  { code: 'SL', nameEn: 'Sierra Leone', nameZh: '塞拉利昂', phoneCode: '232', flag: '🇸🇱' },
  { code: 'SO', nameEn: 'Somalia', nameZh: '索马里', phoneCode: '252', flag: '🇸🇴' },
  { code: 'ZA', nameEn: 'South Africa', nameZh: '南非', phoneCode: '27', flag: '🇿🇦' },
  { code: 'SS', nameEn: 'South Sudan', nameZh: '南苏丹', phoneCode: '211', flag: '🇸🇸' },
  { code: 'SD', nameEn: 'Sudan', nameZh: '苏丹', phoneCode: '249', flag: '🇸🇩' },
  { code: 'TZ', nameEn: 'Tanzania', nameZh: '坦桑尼亚', phoneCode: '255', flag: '🇹🇿' },
  { code: 'TG', nameEn: 'Togo', nameZh: '多哥', phoneCode: '228', flag: '🇹🇬' },
  { code: 'TN', nameEn: 'Tunisia', nameZh: '突尼斯', phoneCode: '216', flag: '🇹🇳' },
  { code: 'UG', nameEn: 'Uganda', nameZh: '乌干达', phoneCode: '256', flag: '🇺🇬' },
  { code: 'ZM', nameEn: 'Zambia', nameZh: '赞比亚', phoneCode: '260', flag: '🇿🇲' },
  { code: 'ZW', nameEn: 'Zimbabwe', nameZh: '津巴布韦', phoneCode: '263', flag: '🇿🇼' },

  // 北美洲
  { code: 'AG', nameEn: 'Antigua and Barbuda', nameZh: '安提瓜和巴布达', phoneCode: '1268', flag: '🇦🇬' },
  { code: 'BS', nameEn: 'Bahamas', nameZh: '巴哈马', phoneCode: '1242', flag: '🇧🇸' },
  { code: 'BB', nameEn: 'Barbados', nameZh: '巴巴多斯', phoneCode: '1246', flag: '🇧🇧' },
  { code: 'BZ', nameEn: 'Belize', nameZh: '伯利兹', phoneCode: '501', flag: '🇧🇿' },
  { code: 'CR', nameEn: 'Costa Rica', nameZh: '哥斯达黎加', phoneCode: '506', flag: '🇨🇷' },
  { code: 'CU', nameEn: 'Cuba', nameZh: '古巴', phoneCode: '53', flag: '🇨🇺' },
  { code: 'DM', nameEn: 'Dominica', nameZh: '多米尼克', phoneCode: '1767', flag: '🇩🇲' },
  { code: 'DO', nameEn: 'Dominican Republic', nameZh: '多米尼加', phoneCode: '1809', flag: '🇩🇴' },
  { code: 'SV', nameEn: 'El Salvador', nameZh: '萨尔瓦多', phoneCode: '503', flag: '🇸🇻' },
  { code: 'GD', nameEn: 'Grenada', nameZh: '格林纳达', phoneCode: '1473', flag: '🇬🇩' },
  { code: 'GT', nameEn: 'Guatemala', nameZh: '危地马拉', phoneCode: '502', flag: '🇬🇹' },
  { code: 'HT', nameEn: 'Haiti', nameZh: '海地', phoneCode: '509', flag: '🇭🇹' },
  { code: 'HN', nameEn: 'Honduras', nameZh: '洪都拉斯', phoneCode: '504', flag: '🇭🇳' },
  { code: 'JM', nameEn: 'Jamaica', nameZh: '牙买加', phoneCode: '1876', flag: '🇯🇲' },
  { code: 'MX', nameEn: 'Mexico', nameZh: '墨西哥', phoneCode: '52', flag: '🇲🇽' },
  { code: 'NI', nameEn: 'Nicaragua', nameZh: '尼加拉瓜', phoneCode: '505', flag: '🇳🇮' },
  { code: 'PA', nameEn: 'Panama', nameZh: '巴拿马', phoneCode: '507', flag: '🇵🇦' },
  { code: 'KN', nameEn: 'Saint Kitts and Nevis', nameZh: '圣基茨和尼维斯', phoneCode: '1869', flag: '🇰🇳' },
  { code: 'LC', nameEn: 'Saint Lucia', nameZh: '圣卢西亚', phoneCode: '1758', flag: '🇱🇨' },
  { code: 'VC', nameEn: 'Saint Vincent and the Grenadines', nameZh: '圣文森特和格林纳丁斯', phoneCode: '1784', flag: '🇻🇨' },
  { code: 'TT', nameEn: 'Trinidad and Tobago', nameZh: '特立尼达和多巴哥', phoneCode: '1868', flag: '🇹🇹' },

  // 南美洲
  { code: 'AR', nameEn: 'Argentina', nameZh: '阿根廷', phoneCode: '54', flag: '🇦🇷' },
  { code: 'BO', nameEn: 'Bolivia', nameZh: '玻利维亚', phoneCode: '591', flag: '🇧🇴' },
  { code: 'BR', nameEn: 'Brazil', nameZh: '巴西', phoneCode: '55', flag: '🇧🇷' },
  { code: 'CL', nameEn: 'Chile', nameZh: '智利', phoneCode: '56', flag: '🇨🇱' },
  { code: 'CO', nameEn: 'Colombia', nameZh: '哥伦比亚', phoneCode: '57', flag: '🇨🇴' },
  { code: 'EC', nameEn: 'Ecuador', nameZh: '厄瓜多尔', phoneCode: '593', flag: '🇪🇨' },
  { code: 'GY', nameEn: 'Guyana', nameZh: '圭亚那', phoneCode: '592', flag: '🇬🇾' },
  { code: 'PY', nameEn: 'Paraguay', nameZh: '巴拉圭', phoneCode: '595', flag: '🇵🇾' },
  { code: 'PE', nameEn: 'Peru', nameZh: '秘鲁', phoneCode: '51', flag: '🇵🇪' },
  { code: 'SR', nameEn: 'Suriname', nameZh: '苏里南', phoneCode: '597', flag: '🇸🇷' },
  { code: 'UY', nameEn: 'Uruguay', nameZh: '乌拉圭', phoneCode: '598', flag: '🇺🇾' },
  { code: 'VE', nameEn: 'Venezuela', nameZh: '委内瑞拉', phoneCode: '58', flag: '🇻🇪' },

  // 大洋洲
  { code: 'FJ', nameEn: 'Fiji', nameZh: '斐济', phoneCode: '679', flag: '🇫🇯' },
  { code: 'KI', nameEn: 'Kiribati', nameZh: '基里巴斯', phoneCode: '686', flag: '🇰🇮' },
  { code: 'MH', nameEn: 'Marshall Islands', nameZh: '马绍尔群岛', phoneCode: '692', flag: '🇲🇭' },
  { code: 'FM', nameEn: 'Micronesia', nameZh: '密克罗尼西亚', phoneCode: '691', flag: '🇫🇲' },
  { code: 'NR', nameEn: 'Nauru', nameZh: '瑙鲁', phoneCode: '674', flag: '🇳🇷' },
  { code: 'NZ', nameEn: 'New Zealand', nameZh: '新西兰', phoneCode: '64', flag: '🇳🇿' },
  { code: 'PW', nameEn: 'Palau', nameZh: '帕劳', phoneCode: '680', flag: '🇵🇼' },
  { code: 'PG', nameEn: 'Papua New Guinea', nameZh: '巴布亚新几内亚', phoneCode: '675', flag: '🇵🇬' },
  { code: 'WS', nameEn: 'Samoa', nameZh: '萨摩亚', phoneCode: '685', flag: '🇼🇸' },
  { code: 'SB', nameEn: 'Solomon Islands', nameZh: '所罗门群岛', phoneCode: '677', flag: '🇸🇧' },
  { code: 'TO', nameEn: 'Tonga', nameZh: '汤加', phoneCode: '676', flag: '🇹🇴' },
  { code: 'TV', nameEn: 'Tuvalu', nameZh: '图瓦卢', phoneCode: '688', flag: '🇹🇻' },
  { code: 'VU', nameEn: 'Vanuatu', nameZh: '瓦努阿图', phoneCode: '678', flag: '🇻🇺' },
];

/**
 * 按国家代码获取国家信息
 */
export const getCountryByCode = (code: string): CountryData | undefined => {
  return COUNTRIES.find((c) => c.code === code);
};

/**
 * 按手机区号获取国家列表 (可能有多个国家使用相同区号)
 */
export const getCountriesByPhoneCode = (phoneCode: string): CountryData[] => {
  return COUNTRIES.filter((c) => c.phoneCode === phoneCode);
};

/**
 * 获取常用国家列表
 */
export const getPopularCountries = (): CountryData[] => {
  return COUNTRIES.filter((c) => c.popular);
};

/**
 * 获取排序后的国家列表 (常用国家在前)
 */
export const getSortedCountries = (): CountryData[] => {
  const popular = COUNTRIES.filter((c) => c.popular);
  const others = COUNTRIES.filter((c) => !c.popular);
  return [...popular, ...others];
};

/**
 * 获取去重的手机区号列表 (用于手机区号选择器)
 */
export const getUniquePhoneCodes = (): { phoneCode: string; countries: CountryData[] }[] => {
  const phoneCodeMap = new Map<string, CountryData[]>();

  COUNTRIES.forEach((country) => {
    const existing = phoneCodeMap.get(country.phoneCode);
    if (existing) {
      existing.push(country);
    } else {
      phoneCodeMap.set(country.phoneCode, [country]);
    }
  });

  // 按区号数字排序
  return Array.from(phoneCodeMap.entries())
    .sort((a, b) => parseInt(a[0]) - parseInt(b[0]))
    .map(([phoneCode, countries]) => ({
      phoneCode,
      countries,
    }));
};
