#coding: utf-8

from django.utils.translation import pgettext_lazy
from django.utils.importlib import import_module
from django.conf import settings

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


def build_country_choices():
    country_list = getattr(
        settings, 'SATCHLESS_COUNTRY_CHOICES', DEFAULT_COUNTRY_CHOICES)
    if isinstance(country_list, str):
        mod_name, han_name = country_list.rsplit('.', 1)
        module = import_module(mod_name)
        country_list = getattr(module, han_name)
    if hasattr(country_list, '__call__'):
        country_list = country_list()
    country_keys = dict(DEFAULT_COUNTRY_CHOICES)
    countries = []
    for country in country_list:
        if country is None:
            country = (u'', u'---------')
        if isinstance(country, str):
            country = (country, country_keys[country])
        countries.append(country)
    return countries

COUNTRY_CHOICES = build_country_choices()
