const rt = [
  [
    "af",
    // Afghanistan
    "93",
    0,
    null,
    "0"
  ],
  [
    "ax",
    // Åland Islands
    "358",
    1,
    ["18", "4"],
    // (4 is a mobile range shared with FI)
    "0"
  ],
  [
    "al",
    // Albania
    "355",
    0,
    null,
    "0"
  ],
  [
    "dz",
    // Algeria
    "213",
    0,
    null,
    "0"
  ],
  [
    "as",
    // American Samoa
    "1",
    5,
    ["684"],
    "1"
  ],
  [
    "ad",
    // Andorra
    "376"
  ],
  [
    "ao",
    // Angola
    "244"
  ],
  [
    "ai",
    // Anguilla
    "1",
    6,
    ["264"],
    "1"
  ],
  [
    "ag",
    // Antigua and Barbuda
    "1",
    7,
    ["268"],
    "1"
  ],
  [
    "ar",
    // Argentina
    "54",
    0,
    null,
    "0"
  ],
  [
    "am",
    // Armenia
    "374",
    0,
    null,
    "0"
  ],
  [
    "aw",
    // Aruba
    "297"
  ],
  [
    "ac",
    // Ascension Island
    "247"
  ],
  [
    "au",
    // Australia
    "61",
    0,
    ["4"],
    // (mobile range shared with CX and CC)
    "0"
  ],
  [
    "at",
    // Austria
    "43",
    0,
    null,
    "0"
  ],
  [
    "az",
    // Azerbaijan
    "994",
    0,
    null,
    "0"
  ],
  [
    "bs",
    // Bahamas
    "1",
    8,
    ["242"],
    "1"
  ],
  [
    "bh",
    // Bahrain
    "973"
  ],
  [
    "bd",
    // Bangladesh
    "880",
    0,
    null,
    "0"
  ],
  [
    "bb",
    // Barbados
    "1",
    9,
    ["246"],
    "1"
  ],
  [
    "by",
    // Belarus
    "375",
    0,
    null,
    "8"
  ],
  [
    "be",
    // Belgium
    "32",
    0,
    null,
    "0"
  ],
  [
    "bz",
    // Belize
    "501"
  ],
  [
    "bj",
    // Benin
    "229"
  ],
  [
    "bm",
    // Bermuda
    "1",
    10,
    ["441"],
    "1"
  ],
  [
    "bt",
    // Bhutan
    "975"
  ],
  [
    "bo",
    // Bolivia
    "591",
    0,
    null,
    "0"
  ],
  [
    "ba",
    // Bosnia and Herzegovina
    "387",
    0,
    null,
    "0"
  ],
  [
    "bw",
    // Botswana
    "267"
  ],
  [
    "br",
    // Brazil
    "55",
    0,
    null,
    "0"
  ],
  [
    "io",
    // British Indian Ocean Territory
    "246"
  ],
  [
    "vg",
    // British Virgin Islands
    "1",
    11,
    ["284"],
    "1"
  ],
  [
    "bn",
    // Brunei
    "673"
  ],
  [
    "bg",
    // Bulgaria
    "359",
    0,
    null,
    "0"
  ],
  [
    "bf",
    // Burkina Faso
    "226"
  ],
  [
    "bi",
    // Burundi
    "257"
  ],
  [
    "kh",
    // Cambodia
    "855",
    0,
    null,
    "0"
  ],
  [
    "cm",
    // Cameroon
    "237"
  ],
  [
    "ca",
    // Canada
    "1",
    1,
    ["204", "226", "236", "249", "250", "257", "263", "289", "306", "343", "354", "365", "367", "368", "382", "403", "416", "418", "428", "431", "437", "438", "450", "468", "474", "506", "514", "519", "548", "579", "581", "584", "587", "604", "613", "639", "647", "672", "683", "705", "709", "742", "753", "778", "780", "782", "807", "819", "825", "867", "873", "879", "902", "905", "942"],
    "1"
  ],
  [
    "cv",
    // Cape Verde
    "238"
  ],
  [
    "bq",
    // Caribbean Netherlands
    "599",
    1,
    ["3", "4", "7"]
  ],
  [
    "ky",
    // Cayman Islands
    "1",
    12,
    ["345"],
    "1"
  ],
  [
    "cf",
    // Central African Republic
    "236"
  ],
  [
    "td",
    // Chad
    "235"
  ],
  [
    "cl",
    // Chile
    "56"
  ],
  [
    "cn",
    // China
    "86",
    0,
    null,
    "0"
  ],
  [
    "cx",
    // Christmas Island
    "61",
    2,
    ["4", "89164"],
    // (4 is a mobile range shared with AU and CC)
    "0"
  ],
  [
    "cc",
    // Cocos (Keeling) Islands
    "61",
    1,
    ["4", "89162"],
    // (4 is a mobile range shared with AU and CX)
    "0"
  ],
  [
    "co",
    // Colombia
    "57",
    0,
    null,
    "0"
  ],
  [
    "km",
    // Comoros
    "269"
  ],
  [
    "cg",
    // Congo (Brazzaville)
    "242"
  ],
  [
    "cd",
    // Congo (Kinshasa)
    "243",
    0,
    null,
    "0"
  ],
  [
    "ck",
    // Cook Islands
    "682"
  ],
  [
    "cr",
    // Costa Rica
    "506"
  ],
  [
    "ci",
    // Côte d'Ivoire
    "225"
  ],
  [
    "hr",
    // Croatia
    "385",
    0,
    null,
    "0"
  ],
  [
    "cu",
    // Cuba
    "53",
    0,
    null,
    "0"
  ],
  [
    "cw",
    // Curaçao
    "599",
    0
  ],
  [
    "cy",
    // Cyprus
    "357"
  ],
  [
    "cz",
    // Czech Republic
    "420"
  ],
  [
    "dk",
    // Denmark
    "45"
  ],
  [
    "dj",
    // Djibouti
    "253"
  ],
  [
    "dm",
    // Dominica
    "1",
    13,
    ["767"],
    "1"
  ],
  [
    "do",
    // Dominican Republic
    "1",
    2,
    ["809", "829", "849"],
    "1"
  ],
  [
    "ec",
    // Ecuador
    "593",
    0,
    null,
    "0"
  ],
  [
    "eg",
    // Egypt
    "20",
    0,
    null,
    "0"
  ],
  [
    "sv",
    // El Salvador
    "503"
  ],
  [
    "gq",
    // Equatorial Guinea
    "240"
  ],
  [
    "er",
    // Eritrea
    "291",
    0,
    null,
    "0"
  ],
  [
    "ee",
    // Estonia
    "372"
  ],
  [
    "sz",
    // Eswatini
    "268"
  ],
  [
    "et",
    // Ethiopia
    "251",
    0,
    null,
    "0"
  ],
  [
    "fk",
    // Falkland Islands (Malvinas)
    "500"
  ],
  [
    "fo",
    // Faroe Islands
    "298"
  ],
  [
    "fj",
    // Fiji
    "679"
  ],
  [
    "fi",
    // Finland
    "358",
    0,
    ["4"],
    // (mobile range shared with AX)
    "0"
  ],
  [
    "fr",
    // France
    "33",
    0,
    null,
    "0"
  ],
  [
    "gf",
    // French Guiana
    "594",
    0,
    null,
    "0"
  ],
  [
    "pf",
    // French Polynesia
    "689"
  ],
  [
    "ga",
    // Gabon
    "241"
  ],
  [
    "gm",
    // Gambia
    "220"
  ],
  [
    "ge",
    // Georgia
    "995",
    0,
    null,
    "0"
  ],
  [
    "de",
    // Germany
    "49",
    0,
    null,
    "0"
  ],
  [
    "gh",
    // Ghana
    "233",
    0,
    null,
    "0"
  ],
  [
    "gi",
    // Gibraltar
    "350"
  ],
  [
    "gr",
    // Greece
    "30"
  ],
  [
    "gl",
    // Greenland
    "299"
  ],
  [
    "gd",
    // Grenada
    "1",
    14,
    ["473"],
    "1"
  ],
  [
    "gp",
    // Guadeloupe
    "590",
    0,
    null,
    "0"
  ],
  [
    "gu",
    // Guam
    "1",
    15,
    ["671"],
    "1"
  ],
  [
    "gt",
    // Guatemala
    "502"
  ],
  [
    "gg",
    // Guernsey
    "44",
    1,
    ["1481", "7781", "7839", "7911"],
    "0"
  ],
  [
    "gn",
    // Guinea
    "224"
  ],
  [
    "gw",
    // Guinea-Bissau
    "245"
  ],
  [
    "gy",
    // Guyana
    "592"
  ],
  [
    "ht",
    // Haiti
    "509"
  ],
  [
    "hn",
    // Honduras
    "504"
  ],
  [
    "hk",
    // Hong Kong SAR China
    "852"
  ],
  [
    "hu",
    // Hungary
    "36",
    0,
    null,
    "06"
  ],
  [
    "is",
    // Iceland
    "354"
  ],
  [
    "in",
    // India
    "91",
    0,
    null,
    "0"
  ],
  [
    "id",
    // Indonesia
    "62",
    0,
    null,
    "0"
  ],
  [
    "ir",
    // Iran
    "98",
    0,
    null,
    "0"
  ],
  [
    "iq",
    // Iraq
    "964",
    0,
    null,
    "0"
  ],
  [
    "ie",
    // Ireland
    "353",
    0,
    null,
    "0"
  ],
  [
    "im",
    // Isle of Man
    "44",
    2,
    ["1624", "74576", "7524", "7624", "7924"],
    "0"
  ],
  [
    "il",
    // Israel
    "972",
    0,
    null,
    "0"
  ],
  [
    "it",
    // Italy
    "39",
    0,
    ["3"]
    // (mobile range shared with VA)
  ],
  [
    "jm",
    // Jamaica
    "1",
    4,
    ["658", "876"],
    "1"
  ],
  [
    "jp",
    // Japan
    "81",
    0,
    null,
    "0"
  ],
  [
    "je",
    // Jersey
    "44",
    3,
    ["1534", "7509", "7700", "7797", "7829", "7937"],
    "0"
  ],
  [
    "jo",
    // Jordan
    "962",
    0,
    null,
    "0"
  ],
  [
    "kz",
    // Kazakhstan
    "7",
    1,
    ["33", "7"],
    // (33 is shared with RU)
    "8"
  ],
  [
    "ke",
    // Kenya
    "254",
    0,
    null,
    "0"
  ],
  [
    "ki",
    // Kiribati
    "686",
    0,
    null,
    "0"
  ],
  [
    "xk",
    // Kosovo
    "383",
    0,
    null,
    "0"
  ],
  [
    "kw",
    // Kuwait
    "965"
  ],
  [
    "kg",
    // Kyrgyzstan
    "996",
    0,
    null,
    "0"
  ],
  [
    "la",
    // Laos
    "856",
    0,
    null,
    "0"
  ],
  [
    "lv",
    // Latvia
    "371"
  ],
  [
    "lb",
    // Lebanon
    "961",
    0,
    null,
    "0"
  ],
  [
    "ls",
    // Lesotho
    "266"
  ],
  [
    "lr",
    // Liberia
    "231",
    0,
    null,
    "0"
  ],
  [
    "ly",
    // Libya
    "218",
    0,
    null,
    "0"
  ],
  [
    "li",
    // Liechtenstein
    "423",
    0,
    null,
    "0"
  ],
  [
    "lt",
    // Lithuania
    "370",
    0,
    null,
    "0"
  ],
  [
    "lu",
    // Luxembourg
    "352"
  ],
  [
    "mo",
    // Macao SAR China
    "853"
  ],
  [
    "mg",
    // Madagascar
    "261",
    0,
    null,
    "0"
  ],
  [
    "mw",
    // Malawi
    "265",
    0,
    null,
    "0"
  ],
  [
    "my",
    // Malaysia
    "60",
    0,
    null,
    "0"
  ],
  [
    "mv",
    // Maldives
    "960"
  ],
  [
    "ml",
    // Mali
    "223"
  ],
  [
    "mt",
    // Malta
    "356"
  ],
  [
    "mh",
    // Marshall Islands
    "692",
    0,
    null,
    "1"
  ],
  [
    "mq",
    // Martinique
    "596",
    0,
    null,
    "0"
  ],
  [
    "mr",
    // Mauritania
    "222"
  ],
  [
    "mu",
    // Mauritius
    "230"
  ],
  [
    "yt",
    // Mayotte
    "262",
    1,
    ["269", "639"],
    "0"
  ],
  [
    "mx",
    // Mexico
    "52"
  ],
  [
    "fm",
    // Micronesia
    "691"
  ],
  [
    "md",
    // Moldova
    "373",
    0,
    null,
    "0"
  ],
  [
    "mc",
    // Monaco
    "377",
    0,
    null,
    "0"
  ],
  [
    "mn",
    // Mongolia
    "976",
    0,
    null,
    "0"
  ],
  [
    "me",
    // Montenegro
    "382",
    0,
    null,
    "0"
  ],
  [
    "ms",
    // Montserrat
    "1",
    16,
    ["664"],
    "1"
  ],
  [
    "ma",
    // Morocco
    "212",
    0,
    ["6", "7"],
    // (mobile ranges shared with EH)
    "0"
  ],
  [
    "mz",
    // Mozambique
    "258"
  ],
  [
    "mm",
    // Myanmar (Burma)
    "95",
    0,
    null,
    "0"
  ],
  [
    "na",
    // Namibia
    "264",
    0,
    null,
    "0"
  ],
  [
    "nr",
    // Nauru
    "674"
  ],
  [
    "np",
    // Nepal
    "977",
    0,
    null,
    "0"
  ],
  [
    "nl",
    // Netherlands
    "31",
    0,
    null,
    "0"
  ],
  [
    "nc",
    // New Caledonia
    "687"
  ],
  [
    "nz",
    // New Zealand
    "64",
    0,
    null,
    "0"
  ],
  [
    "ni",
    // Nicaragua
    "505"
  ],
  [
    "ne",
    // Niger
    "227"
  ],
  [
    "ng",
    // Nigeria
    "234",
    0,
    null,
    "0"
  ],
  [
    "nu",
    // Niue
    "683"
  ],
  [
    "nf",
    // Norfolk Island
    "672"
  ],
  [
    "kp",
    // North Korea
    "850",
    0,
    null,
    "0"
  ],
  [
    "mk",
    // North Macedonia
    "389",
    0,
    null,
    "0"
  ],
  [
    "mp",
    // Northern Mariana Islands
    "1",
    17,
    ["670"],
    "1"
  ],
  [
    "no",
    // Norway
    "47",
    0,
    ["4", "9"]
    // (mobile ranges shared with SJ)
  ],
  [
    "om",
    // Oman
    "968"
  ],
  [
    "pk",
    // Pakistan
    "92",
    0,
    null,
    "0"
  ],
  [
    "pw",
    // Palau
    "680"
  ],
  [
    "ps",
    // Palestinian Territories
    "970",
    0,
    null,
    "0"
  ],
  [
    "pa",
    // Panama
    "507"
  ],
  [
    "pg",
    // Papua New Guinea
    "675"
  ],
  [
    "py",
    // Paraguay
    "595",
    0,
    null,
    "0"
  ],
  [
    "pe",
    // Peru
    "51",
    0,
    null,
    "0"
  ],
  [
    "ph",
    // Philippines
    "63",
    0,
    null,
    "0"
  ],
  [
    "pl",
    // Poland
    "48"
  ],
  [
    "pt",
    // Portugal
    "351"
  ],
  [
    "pr",
    // Puerto Rico
    "1",
    3,
    ["787", "939"],
    "1"
  ],
  [
    "qa",
    // Qatar
    "974"
  ],
  [
    "re",
    // Réunion
    "262",
    0,
    null,
    "0"
  ],
  [
    "ro",
    // Romania
    "40",
    0,
    null,
    "0"
  ],
  [
    "ru",
    // Russia
    "7",
    0,
    ["33"],
    // (shared with KZ)
    "8"
  ],
  [
    "rw",
    // Rwanda
    "250",
    0,
    null,
    "0"
  ],
  [
    "ws",
    // Samoa
    "685"
  ],
  [
    "sm",
    // San Marino
    "378"
  ],
  [
    "st",
    // São Tomé & Príncipe
    "239"
  ],
  [
    "sa",
    // Saudi Arabia
    "966",
    0,
    null,
    "0"
  ],
  [
    "sn",
    // Senegal
    "221"
  ],
  [
    "rs",
    // Serbia
    "381",
    0,
    null,
    "0"
  ],
  [
    "sc",
    // Seychelles
    "248"
  ],
  [
    "sl",
    // Sierra Leone
    "232",
    0,
    null,
    "0"
  ],
  [
    "sg",
    // Singapore
    "65"
  ],
  [
    "sx",
    // Sint Maarten
    "1",
    21,
    ["721"],
    "1"
  ],
  [
    "sk",
    // Slovakia
    "421",
    0,
    null,
    "0"
  ],
  [
    "si",
    // Slovenia
    "386",
    0,
    null,
    "0"
  ],
  [
    "sb",
    // Solomon Islands
    "677"
  ],
  [
    "so",
    // Somalia
    "252",
    0,
    null,
    "0"
  ],
  [
    "za",
    // South Africa
    "27",
    0,
    null,
    "0"
  ],
  [
    "kr",
    // South Korea
    "82",
    0,
    null,
    "0"
  ],
  [
    "ss",
    // South Sudan
    "211",
    0,
    null,
    "0"
  ],
  [
    "es",
    // Spain
    "34"
  ],
  [
    "lk",
    // Sri Lanka
    "94",
    0,
    null,
    "0"
  ],
  [
    "bl",
    // St. Barthélemy
    "590",
    1,
    null,
    "0"
  ],
  [
    "sh",
    // St. Helena
    "290"
  ],
  [
    "kn",
    // St. Kitts & Nevis
    "1",
    18,
    ["869"],
    "1"
  ],
  [
    "lc",
    // St. Lucia
    "1",
    19,
    ["758"],
    "1"
  ],
  [
    "mf",
    // St. Martin
    "590",
    2,
    null,
    "0"
  ],
  [
    "pm",
    // St. Pierre & Miquelon
    "508",
    0,
    null,
    "0"
  ],
  [
    "vc",
    // St. Vincent & Grenadines
    "1",
    20,
    ["784"],
    "1"
  ],
  [
    "sd",
    // Sudan
    "249",
    0,
    null,
    "0"
  ],
  [
    "sr",
    // Suriname
    "597"
  ],
  [
    "sj",
    // Svalbard & Jan Mayen
    "47",
    1,
    ["4", "79", "9"]
    // (4 and 9 are mobile ranges shared with NO)
  ],
  [
    "se",
    // Sweden
    "46",
    0,
    null,
    "0"
  ],
  [
    "ch",
    // Switzerland
    "41",
    0,
    null,
    "0"
  ],
  [
    "sy",
    // Syria
    "963",
    0,
    null,
    "0"
  ],
  [
    "tw",
    // Taiwan
    "886",
    0,
    null,
    "0"
  ],
  [
    "tj",
    // Tajikistan
    "992"
  ],
  [
    "tz",
    // Tanzania
    "255",
    0,
    null,
    "0"
  ],
  [
    "th",
    // Thailand
    "66",
    0,
    null,
    "0"
  ],
  [
    "tl",
    // Timor-Leste
    "670"
  ],
  [
    "tg",
    // Togo
    "228"
  ],
  [
    "tk",
    // Tokelau
    "690"
  ],
  [
    "to",
    // Tonga
    "676"
  ],
  [
    "tt",
    // Trinidad & Tobago
    "1",
    22,
    ["868"],
    "1"
  ],
  [
    "tn",
    // Tunisia
    "216"
  ],
  [
    "tr",
    // Turkey
    "90",
    0,
    null,
    "0"
  ],
  [
    "tm",
    // Turkmenistan
    "993",
    0,
    null,
    "8"
  ],
  [
    "tc",
    // Turks & Caicos Islands
    "1",
    23,
    ["649"],
    "1"
  ],
  [
    "tv",
    // Tuvalu
    "688"
  ],
  [
    "vi",
    // U.S. Virgin Islands
    "1",
    24,
    ["340"],
    "1"
  ],
  [
    "ug",
    // Uganda
    "256",
    0,
    null,
    "0"
  ],
  [
    "ua",
    // Ukraine
    "380",
    0,
    null,
    "0"
  ],
  [
    "ae",
    // United Arab Emirates
    "971",
    0,
    null,
    "0"
  ],
  [
    "gb",
    // United Kingdom
    "44",
    0,
    null,
    "0"
  ],
  [
    "us",
    // United States
    "1",
    0,
    null,
    "1"
  ],
  [
    "uy",
    // Uruguay
    "598",
    0,
    null,
    "0"
  ],
  [
    "uz",
    // Uzbekistan
    "998"
  ],
  [
    "vu",
    // Vanuatu
    "678"
  ],
  [
    "va",
    // Vatican City
    "39",
    1,
    ["06698", "3"]
    // (3 is a mobile range shared with IT)
  ],
  [
    "ve",
    // Venezuela
    "58",
    0,
    null,
    "0"
  ],
  [
    "vn",
    // Vietnam
    "84",
    0,
    null,
    "0"
  ],
  [
    "wf",
    // Wallis & Futuna
    "681"
  ],
  [
    "eh",
    // Western Sahara
    "212",
    1,
    ["5288", "5289", "6", "7"],
    // (6 and 7 are mobile ranges shared with MA)
    "0"
  ],
  [
    "ye",
    // Yemen
    "967",
    0,
    null,
    "0"
  ],
  [
    "zm",
    // Zambia
    "260",
    0,
    null,
    "0"
  ],
  [
    "zw",
    // Zimbabwe
    "263",
    0,
    null,
    "0"
  ]
], S = [];
for (const r of rt)
  S.push({
    name: "",
    // populated in the plugin
    iso2: r[0],
    dialCode: r[1],
    priority: r[2] || 0,
    areaCodes: r[3] || null,
    nodeById: {},
    // populated by the plugin
    nationalPrefix: r[4] || null,
    normalisedName: "",
    // populated in the plugin
    initials: "",
    // populated in the plugin
    dialCodePlus: ""
    // populated in the plugin
  });
const k = {
  OPEN_COUNTRY_DROPDOWN: "open:countrydropdown",
  CLOSE_COUNTRY_DROPDOWN: "close:countrydropdown",
  COUNTRY_CHANGE: "countrychange",
  INPUT: "input"
  // used for synthetic input trigger
}, h = {
  HIDE: "iti__hide",
  V_HIDE: "iti__v-hide",
  ARROW_UP: "iti__arrow--up",
  GLOBE: "iti__globe",
  FLAG: "iti__flag",
  LOADING: "iti__loading",
  COUNTRY_ITEM: "iti__country",
  HIGHLIGHT: "iti__highlight"
}, g = {
  ARROW_UP: "ArrowUp",
  ARROW_DOWN: "ArrowDown",
  SPACE: " ",
  ENTER: "Enter",
  ESC: "Escape",
  TAB: "Tab"
}, G = {
  PASTE: "insertFromPaste",
  DELETE_FWD: "deleteContentForward"
}, A = {
  ALPHA_UNICODE: new RegExp("\\p{L}", "u"),
  // any kind of letter from any language
  NON_PLUS_NUMERIC: /[^+0-9]/,
  // chars that are NOT + or digit
  NON_PLUS_NUMERIC_GLOBAL: /[^+0-9]/g,
  // chars that are NOT + or digit (global)
  HIDDEN_SEARCH_CHAR: /^[a-zA-ZÀ-ÿа-яА-Я ]$/
  // single acceptable hidden-search char
}, tt = {
  SEARCH_DEBOUNCE_MS: 100,
  HIDDEN_SEARCH_RESET_MS: 1e3
}, j = {
  UNKNOWN_NUMBER_TYPE: -99,
  UNKNOWN_VALIDATION_ERROR: -99
}, T = {
  SANE_SELECTED_WITH_DIAL_WIDTH: 78,
  // px width fallback when separateDialCode enabled
  SANE_SELECTED_NO_DIAL_WIDTH: 42,
  // px width fallback when no separate dial code
  INPUT_PADDING_EXTRA_LEFT: 6,
  // px gap between selected country container and input text
  DROPDOWN_MARGIN: 3,
  // px margin between dropdown and tel input
  SANE_DROPDOWN_HEIGHT: 200
  // px height fallback for dropdown
}, et = {
  NANP: "1"
  // North American Numbering Plan
}, B = {
  DIAL_CODE: "44",
  // +44 United Kingdom
  MOBILE_PREFIX: "7",
  // UK mobile numbers start with 7 after national trunk (0) or core section
  MOBILE_CORE_LENGTH: 10
  // core number length (excluding dial code / national prefix) for mobiles
}, lt = {
  ISO2: "us"
}, U = {
  AGGRESSIVE: "aggressive",
  POLITE: "polite",
  OFF: "off"
}, P = {
  AUTO: "auto"
}, at = [
  "FIXED_LINE",
  "MOBILE",
  "FIXED_LINE_OR_MOBILE",
  "TOLL_FREE",
  "PREMIUM_RATE",
  "SHARED_COST",
  "VOIP",
  "PERSONAL_NUMBER",
  "PAGER",
  "UAN",
  "VOICEMAIL",
  "UNKNOWN"
], x = new Set(at), K = {
  COUNTRY_CODE: "countryCode",
  DIAL_CODE: "dialCode"
}, p = {
  EXPANDED: "aria-expanded",
  LABEL: "aria-label",
  SELECTED: "aria-selected",
  ACTIVE_DESCENDANT: "aria-activedescendant",
  HASPOPUP: "aria-haspopup",
  CONTROLS: "aria-controls",
  HIDDEN: "aria-hidden",
  AUTOCOMPLETE: "aria-autocomplete",
  MODAL: "aria-modal"
}, ut = {
  selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})",
  noCountrySelected: "Select country",
  countryListAriaLabel: "List of countries",
  searchPlaceholder: "Search",
  clearSearchAriaLabel: "Clear search",
  searchEmptyState: "No results found",
  searchSummaryAria(r) {
    return r === 0 ? "No results found" : r === 1 ? "1 result found" : `${r} results found`;
  }
}, F = (r) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(r).matches, ct = () => {
  if (typeof navigator < "u" && typeof window < "u") {
    const r = F("(max-width: 500px)"), t = F("(max-height: 600px)"), e = F("(pointer: coarse)");
    return r || e && t;
  }
  return !1;
}, V = {
  //* Whether or not to allow the dropdown.
  allowDropdown: !0,
  //* The number type to enforce during validation.
  allowedNumberTypes: ["MOBILE", "FIXED_LINE"],
  //* Whether or not to allow extensions after the main number.
  allowNumberExtensions: !1,
  // Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
  allowPhonewords: !1,
  //* Add a placeholder in the input with an example number for the selected country.
  autoPlaceholder: U.POLITE,
  //* Add a custom class to the (injected) container element.
  containerClass: "",
  //* Locale for localising country names via Intl.DisplayNames.
  countryNameLocale: "en",
  //* The order of the countries in the dropdown. Defaults to alphabetical.
  countryOrder: null,
  //* Add a country search input at the top of the dropdown.
  countrySearch: !0,
  //* Modify the auto placeholder.
  customPlaceholder: null,
  //* Always show the dropdown
  dropdownAlwaysOpen: !1,
  //* Append menu to specified element.
  dropdownContainer: null,
  //* Don't display these countries.
  excludeCountries: [],
  //* Fix the dropdown width to the input width (rather than being as wide as the longest country name).
  fixDropdownWidth: !0,
  //* Format the number as the user types
  formatAsYouType: !0,
  //* Format the input value during initialisation and on setNumber.
  formatOnDisplay: !0,
  //* geoIp lookup function.
  geoIpLookup: null,
  //* Inject a hidden input with the name returned from this function, and on submit, populate it with the result of getNumber.
  hiddenInput: null,
  //* Internationalise the plugin text e.g. search input placeholder, country names.
  i18n: {},
  //* Initial country.
  initialCountry: "",
  //* A function to load the utils script.
  loadUtils: null,
  //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers.
  nationalMode: !0,
  //* Display only these countries.
  onlyCountries: [],
  //* Number type to use for placeholders.
  placeholderNumberType: "MOBILE",
  //* Add custom classes to the search input element.
  searchInputClass: "",
  //* Display the international dial code next to the selected flag.
  separateDialCode: !1,
  //* Show flags - for both the selected country, and in the country dropdown
  showFlags: !0,
  //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
  strictMode: !1,
  //* Use full screen popup instead of dropdown for country list.
  useFullscreenPopup: ct()
}, st = (r) => JSON.stringify(r), Y = (r) => !!r && typeof r == "object" && !Array.isArray(r), dt = (r) => typeof r == "function", ht = (r) => {
  if (!r || typeof r != "object") return !1;
  const t = r;
  return t.nodeType === 1 && typeof t.tagName == "string" && typeof t.appendChild == "function";
}, pt = new Set(S.map((r) => r.iso2)), it = (r) => pt.has(r), z = new Set(Object.values(U)), H = (r) => {
  console.warn(`[intl-tel-input] ${r}`);
}, _ = (r, t, e) => {
  H(`Option '${r}' must be ${t}; got ${st(e)}. Ignoring.`);
}, Ct = (r, t) => Object.prototype.hasOwnProperty.call(r, t), q = (r, t) => {
  const e = "an array of ISO2 country code strings";
  if (!Array.isArray(t))
    return _(r, e, t), !1;
  for (const s of t) {
    if (typeof s != "string")
      return _(r, e, t), !1;
    const i = s.toLowerCase();
    if (!it(i))
      return H(`Invalid country code in '${r}': '${s}'. Ignoring.`), !1;
  }
  return !0;
}, ft = (r) => {
  if (r === void 0)
    return {};
  if (!Y(r)) {
    const e = `The second argument must be an options object; got ${st(r)}. Using defaults.`;
    return H(e), {};
  }
  const t = {};
  for (const [e, s] of Object.entries(r)) {
    if (!Ct(V, e)) {
      H(`Unknown option '${e}'. Ignoring.`);
      continue;
    }
    switch (e) {
      case "allowDropdown":
      case "allowNumberExtensions":
      case "allowPhonewords":
      case "countrySearch":
      case "dropdownAlwaysOpen":
      case "fixDropdownWidth":
      case "formatAsYouType":
      case "formatOnDisplay":
      case "nationalMode":
      case "showFlags":
      case "separateDialCode":
      case "strictMode":
      case "useFullscreenPopup":
        if (typeof s != "boolean") {
          _(e, "a boolean", s);
          break;
        }
        t[e] = s;
        break;
      case "autoPlaceholder":
        if (typeof s != "string" || !z.has(s)) {
          const i = Array.from(z).join(", ");
          _("autoPlaceholder", `one of ${i}`, s);
          break;
        }
        t[e] = s;
        break;
      case "containerClass":
      case "searchInputClass":
      case "countryNameLocale":
        if (typeof s != "string") {
          _(e, "a string", s);
          break;
        }
        t[e] = s;
        break;
      case "countryOrder":
        (s === null || q(e, s)) && (t[e] = s);
        break;
      case "customPlaceholder":
      case "geoIpLookup":
      case "hiddenInput":
      case "loadUtils":
        if (s !== null && !dt(s)) {
          _(e, "a function or null", s);
          break;
        }
        t[e] = s;
        break;
      case "dropdownContainer":
        if (s !== null && !ht(s)) {
          _("dropdownContainer", "an HTMLElement or null", s);
          break;
        }
        t[e] = s;
        break;
      case "excludeCountries":
      case "onlyCountries":
        q(e, s) && (t[e] = s);
        break;
      case "i18n":
        if (s && !Y(s)) {
          _("i18n", "an object", s);
          break;
        }
        t[e] = s;
        break;
      case "initialCountry": {
        if (typeof s != "string") {
          _("initialCountry", "a string", s);
          break;
        }
        const i = s.toLowerCase();
        if (i && i !== P.AUTO && !it(i)) {
          _("initialCountry", "a valid ISO2 country code or 'auto'", s);
          break;
        }
        t[e] = s;
        break;
      }
      case "placeholderNumberType":
        if (typeof s != "string" || !x.has(s)) {
          const i = Array.from(x).join(", ");
          _("placeholderNumberType", `one of ${i}`, s);
          break;
        }
        t[e] = s;
        break;
      case "allowedNumberTypes":
        if (s !== null) {
          if (!Array.isArray(s)) {
            _("allowedNumberTypes", "an array of number types or null", s);
            break;
          }
          let i = !0;
          for (const n of s)
            if (typeof n != "string" || !x.has(n)) {
              const o = Array.from(x).join(", ");
              _("allowedNumberTypes", `an array of valid number types (${o})`, n), i = !1;
              break;
            }
          i && (t[e] = s);
        } else
          t[e] = null;
        break;
    }
  }
  return t;
}, yt = (r) => {
  r.dropdownAlwaysOpen && (r.useFullscreenPopup = !1, r.allowDropdown = !0), r.useFullscreenPopup && (r.fixDropdownWidth = !1), r.onlyCountries.length === 1 && (r.initialCountry = r.onlyCountries[0]), r.separateDialCode && (r.nationalMode = !1), r.allowDropdown && !r.showFlags && !r.separateDialCode && (r.nationalMode = !1), r.useFullscreenPopup && !r.dropdownContainer && (r.dropdownContainer = document.body), r.i18n = { ...ut, ...r.i18n };
}, O = (r) => r.replace(/\D/g, ""), nt = (r = "") => r.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), mt = () => typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, gt = (r, t) => {
  const e = nt(t), s = [], i = [], n = [], o = [], l = [], a = [];
  for (const d of r)
    d.iso2 === e ? s.push(d) : d.normalisedName.startsWith(e) ? i.push(d) : d.normalisedName.includes(e) ? n.push(d) : e === d.dialCode || e === d.dialCodePlus ? o.push(d) : d.dialCodePlus.includes(e) ? l.push(d) : d.initials.includes(e) && a.push(d);
  const c = (d, f) => d.priority - f.priority;
  return [
    ...s.sort(c),
    ...i.sort(c),
    ...n.sort(c),
    ...o.sort(c),
    ...l.sort(c),
    ...a.sort(c)
  ];
}, It = (r, t) => {
  const e = t.toLowerCase();
  for (const s of r)
    if (s.name.toLowerCase().startsWith(e))
      return s;
  return null;
}, W = (r) => Object.keys(r).filter((t) => !!r[t]).join(" "), C = (r, t, e) => {
  const s = document.createElement(r);
  return t && Object.entries(t).forEach(
    ([i, n]) => s.setAttribute(i, n)
  ), e && e.appendChild(s), s;
}, _t = () => `
  <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" ${p.HIDDEN}="true">
    <circle cx="11" cy="11" r="7" />
    <line x1="21" y1="21" x2="16.65" y2="16.65" />
  </svg>`, bt = (r) => {
  const t = `iti-${r}-clear-mask`;
  return `
    <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" ${p.HIDDEN}="true" focusable="false">
      <mask id="${t}" maskUnits="userSpaceOnUse">
        <rect width="16" height="16" fill="white" />
        <path d="M5.2 5.2 L10.8 10.8 M10.8 5.2 L5.2 10.8" stroke="black" stroke-linecap="round" class="iti__search-clear-x" />
      </mask>
      <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${t})" />
    </svg>`;
}, wt = () => `
  <svg class="iti__country-check-svg" width="14" height="14" viewBox="0 0 16 16" fill="currentColor" focusable="false" ${p.HIDDEN}="true">
    <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
  </svg>`, X = () => `
  <svg width="256" height="256" viewBox="0 0 512 512" class="iti__globe-svg">
    <path d="M508 213a240 240 0 0 0-449-87l-2 5-2 5c-8 14-13 30-17 46a65 65 0 0 1 56 4c16-10 35-19 56-27l9-3c-6 23-10 48-10 74h-16l4 6c3 4 5 8 6 13h6c0 22 3 44 8 65l2 10-25-10-4 5 12 18 9 3 6 2 8 3 9 26 1 2 16-7h1l-5-13-1-2c24 6 49 9 75 10v26l11 10 7 7v-30l1-13c22 0 44-3 65-8l10-2-21 48-1 1a317 317 0 0 1-14 23l-21 5h-2c6 16 7 33 1 50a240 240 0 0 0 211-265m-401-56-11 6c19-44 54-79 98-98-11 20-21 44-29 69-21 6-40 15-58 23m154 182v4c-29-1-57-6-81-13-7-25-12-52-13-81h94zm0-109h-94c1-29 6-56 13-81 24-7 52-12 81-13zm0-112c-22 1-44 4-65 8l-10 2 12-30 9-17 1-2a332 332 0 0 1 13-23c13-4 26-6 40-7zm187 69 6 4c4 12 6 25 6 38v1h-68c-1-26-4-51-10-74l48 20 1 1 14 8zm-14-44 10 20c-20-11-43-21-68-29-8-25-18-49-29-69 37 16 67 44 87 78M279 49h1c13 1 27 3 39 7l14 23 1 2a343 343 0 0 1 12 26l2 5 6 16c-23-6-48-9-74-10h-1zm0 87h1c29 1 56 6 81 13 7 24 12 51 12 80v1h-94zm2 207h-2v-94h95c-1 29-6 56-13 81-24 7-51 12-80 13m86 60-20 10c11-20 21-43 29-68 25-8 48-18 68-29-16 37-43 67-77 87m87-115-7 5-16 9-2 1a337 337 0 0 1-47 21c6-24 9-49 10-75h68c0 13-2 27-6 39"/>
    <path d="m261 428-2-2-22-21a40 40 0 0 0-32-11h-1a37 37 0 0 0-18 8l-1 1-4 2-2 2-5 4c-9-3-36-31-47-44s-32-45-34-55l3-2a151 151 0 0 0 11-9v-1a39 39 0 0 0 5-48l-3-3-11-19-3-4-5-7h-1l-3-3-4-3-5-2a35 35 0 0 0-16-3h-5c-4 1-14 5-24 11l-4 2-4 3-4 2c-9 8-17 17-18 27a380 380 0 0 0 212 259h3c12 0 25-10 36-21l10-12 6-11a39 39 0 0 0-8-40"/>
  </svg>`;
class R {
  constructor(t, e, s) {
    this.searchKeyupTimer = null, this.inlineDropdownHeight = null, this.dropdownForContainer = null, this.highlightedItem = null, this.selectedItem = null, t.dataset.intlTelInputId = s.toString(), this.telInput = t, this.options = e, this.id = s, this.hadInitialPlaceholder = !!t.getAttribute("placeholder"), this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.options.separateDialCode && (this.originalPaddingLeft = this.telInput.style.paddingLeft);
  }
  // Validate that the provided element is an HTMLInputElement.
  static validateInput(t) {
    const e = t == null ? void 0 : t.tagName;
    if (!(!!t && typeof t == "object" && e === "INPUT" && typeof t.setAttribute == "function")) {
      const i = Object.prototype.toString.call(t);
      throw new TypeError(
        `The first argument must be an HTMLInputElement, not ${i}`
      );
    }
  }
  //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
  generateMarkup(t) {
    this.countries = t, this.telInput.classList.add("iti__tel-input"), this.telInput.hasAttribute("autocomplete") || this.telInput.setAttribute("autocomplete", "tel"), this.telInput.hasAttribute("inputmode") || this.telInput.setAttribute("inputmode", "tel");
    const e = this._createWrapperAndInsert();
    this._maybeBuildCountryContainer(e), e.appendChild(this.telInput), this._maybeUpdateInputPaddingAndReveal(), this._maybeBuildHiddenInputs(e);
  }
  _createWrapperAndInsert() {
    const {
      allowDropdown: t,
      showFlags: e,
      containerClass: s,
      useFullscreenPopup: i
    } = this.options, n = W({
      iti: !0,
      "iti--allow-dropdown": t,
      "iti--show-flags": e,
      "iti--inline-dropdown": !i,
      [s]: !!s
    }), o = C("div", { class: n });
    return this.isRTL && o.setAttribute("dir", "ltr"), this.telInput.before(o), o;
  }
  _maybeBuildCountryContainer(t) {
    const { allowDropdown: e, separateDialCode: s, showFlags: i } = this.options;
    if (e || i || s) {
      this.countryContainer = C(
        "div",
        // visibly hidden until we measure it's width to set the input padding correctly
        { class: `iti__country-container ${h.V_HIDE}` },
        t
      ), e ? (this.selectedCountry = C(
        "button",
        {
          type: "button",
          class: "iti__selected-country",
          [p.EXPANDED]: "false",
          [p.LABEL]: this.options.i18n.noCountrySelected,
          [p.HASPOPUP]: "dialog",
          [p.CONTROLS]: `iti-${this.id}__dropdown-content`
        },
        this.countryContainer
      ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = C(
        "div",
        { class: "iti__selected-country" },
        this.countryContainer
      );
      const n = C(
        "div",
        { class: "iti__selected-country-primary" },
        this.selectedCountry
      );
      this.selectedCountryInner = C(
        "div",
        { class: h.FLAG },
        n
      ), e && (this.dropdownArrow = C(
        "div",
        { class: "iti__arrow", [p.HIDDEN]: "true" },
        n
      )), s && (this.selectedDialCode = C(
        "div",
        { class: "iti__selected-dial-code" },
        this.selectedCountry
      )), e && this._buildDropdownContent();
    }
  }
  _maybeEnsureDropdownWidthSet() {
    const { fixDropdownWidth: t } = this.options;
    if (t && !this.dropdownContent.style.width) {
      const e = this.telInput.offsetWidth;
      e > 0 && (this.dropdownContent.style.width = `${e}px`);
    }
  }
  _buildDropdownContent() {
    const {
      fixDropdownWidth: t,
      useFullscreenPopup: e,
      countrySearch: s,
      i18n: i,
      dropdownContainer: n,
      containerClass: o
    } = this.options, l = t ? "" : "iti--flexible-dropdown-width";
    if (this.dropdownContent = C("div", {
      id: `iti-${this.id}__dropdown-content`,
      class: `iti__dropdown-content ${h.HIDE} ${l}`,
      role: "dialog",
      [p.MODAL]: "true"
    }), this.isRTL && this.dropdownContent.setAttribute("dir", "rtl"), s && this._buildSearchUI(), this.countryList = C(
      "ul",
      {
        class: "iti__country-list",
        id: `iti-${this.id}__country-listbox`,
        role: "listbox",
        [p.LABEL]: i.countryListAriaLabel
      },
      this.dropdownContent
    ), this._appendListItems(), s && this.updateSearchResultsA11yText(), e || (this._maybeEnsureDropdownWidthSet(), this.inlineDropdownHeight = this.getHiddenInlineDropdownHeight(), s && (this.dropdownContent.style.height = `${this.inlineDropdownHeight}px`)), n) {
      const a = W({
        iti: !0,
        "iti--container": !0,
        "iti--fullscreen-popup": e,
        "iti--inline-dropdown": !e,
        [o]: !!o
      });
      this.dropdownForContainer = C("div", { class: a }), this.dropdownForContainer.appendChild(this.dropdownContent);
    } else
      this.countryContainer.appendChild(this.dropdownContent);
  }
  _buildSearchUI() {
    const { i18n: t, searchInputClass: e } = this.options, s = C(
      "div",
      { class: "iti__search-input-wrapper" },
      this.dropdownContent
    );
    this.searchIcon = C(
      "span",
      {
        class: "iti__search-icon",
        [p.HIDDEN]: "true"
      },
      s
    ), this.searchIcon.innerHTML = _t(), this.searchInput = C(
      "input",
      {
        id: `iti-${this.id}__search-input`,
        // Chrome says inputs need either a name or an id
        type: "search",
        class: `iti__search-input ${e}`,
        placeholder: t.searchPlaceholder,
        // role=combobox + aria-autocomplete=list + aria-activedescendant allows maintaining focus on the search input while allowing users to navigate search results with up/down keyboard keys
        role: "combobox",
        [p.EXPANDED]: "true",
        [p.LABEL]: t.searchPlaceholder,
        [p.CONTROLS]: `iti-${this.id}__country-listbox`,
        [p.AUTOCOMPLETE]: "list",
        autocomplete: "off"
      },
      s
    ), this.searchClearButton = C(
      "button",
      {
        type: "button",
        class: `iti__search-clear ${h.HIDE}`,
        [p.LABEL]: t.clearSearchAriaLabel,
        tabindex: "-1"
      },
      s
    ), this.searchClearButton.innerHTML = bt(this.id), this.searchResultsA11yText = C(
      "span",
      { class: "iti__a11y-text" },
      this.dropdownContent
    ), this.searchNoResults = C(
      "div",
      {
        class: `iti__no-results ${h.HIDE}`,
        [p.HIDDEN]: "true"
        // all a11y messaging happens in this.searchResultsA11yText
      },
      this.dropdownContent
    ), this.searchNoResults.textContent = t.searchEmptyState;
  }
  _maybeUpdateInputPaddingAndReveal() {
    this.countryContainer && (this.updateInputPadding(), this.countryContainer.classList.remove(h.V_HIDE));
  }
  _maybeBuildHiddenInputs(t) {
    var s, i;
    const { hiddenInput: e } = this.options;
    if (e) {
      const n = this.telInput.getAttribute("name") || "", o = e(n);
      if (o.phone) {
        const l = (s = this.telInput.form) == null ? void 0 : s.querySelector(
          `input[name="${o.phone}"]`
        );
        l ? this.hiddenInput = l : (this.hiddenInput = C("input", {
          type: "hidden",
          name: o.phone
        }), t.appendChild(this.hiddenInput));
      }
      if (o.country) {
        const l = (i = this.telInput.form) == null ? void 0 : i.querySelector(
          `input[name="${o.country}"]`
        );
        l ? this.hiddenInputCountry = l : (this.hiddenInputCountry = C("input", {
          type: "hidden",
          name: o.country
        }), t.appendChild(this.hiddenInputCountry));
      }
    }
  }
  //* For each country: add a country list item <li> to the countryList <ul> container.
  _appendListItems() {
    const t = document.createDocumentFragment();
    for (let e = 0; e < this.countries.length; e++) {
      const s = this.countries[e], i = W({
        [h.COUNTRY_ITEM]: !0
      }), n = C("li", {
        id: `iti-${this.id}__item-${s.iso2}`,
        class: i,
        tabindex: "-1",
        role: "option",
        [p.SELECTED]: "false"
      });
      n.dataset.dialCode = s.dialCode, n.dataset.countryCode = s.iso2, s.nodeById[this.id] = n, this.options.showFlags && C("div", { class: `${h.FLAG} iti__${s.iso2}` }, n);
      const o = C("span", { class: "iti__country-name" }, n);
      o.textContent = `${s.name} `;
      const l = C("span", { class: "iti__dial-code" }, o);
      this.isRTL && l.setAttribute("dir", "ltr"), l.textContent = `(+${s.dialCode})`, t.appendChild(n);
    }
    this.countryList.appendChild(t);
  }
  //* Update the input padding to make space for the selected country/dial code.
  updateInputPadding() {
    if (this.selectedCountry) {
      const t = this.options.separateDialCode ? T.SANE_SELECTED_WITH_DIAL_WIDTH : T.SANE_SELECTED_NO_DIAL_WIDTH, s = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || t) + T.INPUT_PADDING_EXTRA_LEFT;
      this.telInput.style.paddingLeft = `${s}px`;
    }
  }
  static getBody() {
    let t;
    try {
      t = window.top.document.body;
    } catch {
      t = document.body;
    }
    return t;
  }
  //* When input is in a hidden container during init, we cannot calculate the selected country width.
  //* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
  //* To get the right styling to apply, all we need is a shallow clone of the container,
  //* and then to inject a deep clone of the selectedCountry element.
  _getHiddenSelectedCountryWidth() {
    if (this.telInput.parentNode) {
      const t = R.getBody(), e = this.telInput.parentNode.cloneNode(
        !1
      );
      e.style.visibility = "hidden", t.appendChild(e);
      const s = this.countryContainer.cloneNode();
      e.appendChild(s);
      const i = this.selectedCountry.cloneNode(
        !0
      );
      s.appendChild(i);
      const n = i.offsetWidth;
      return t.removeChild(e), n;
    }
    return 0;
  }
  // this is run before we add the dropdown to the DOM
  getHiddenInlineDropdownHeight() {
    const t = R.getBody();
    this.dropdownContent.classList.remove(h.HIDE);
    const e = C("div", { class: "iti iti--inline-dropdown" });
    e.appendChild(this.dropdownContent), e.style.visibility = "hidden", t.appendChild(e);
    const s = this.dropdownContent.offsetHeight;
    return t.removeChild(e), e.style.visibility = "", this.dropdownContent.classList.add(h.HIDE), s > 0 ? s : T.SANE_DROPDOWN_HEIGHT;
  }
  //* Update search results text (for a11y).
  updateSearchResultsA11yText() {
    const { i18n: t } = this.options, e = this.countryList.childElementCount;
    this.searchResultsA11yText.textContent = t.searchSummaryAria(e);
  }
  //* Country search: Filter the countries according to the search query.
  filterCountriesByQuery(t) {
    let e;
    t === "" ? e = this.countries : e = gt(this.countries, t), this.filterCountries(e);
  }
  // Search input handlers
  doFilter() {
    const t = this.searchInput.value.trim();
    this.filterCountriesByQuery(t), this.searchInput.value ? this.searchClearButton.classList.remove(h.HIDE) : this.searchClearButton.classList.add(h.HIDE);
  }
  handleSearchChange() {
    this.searchKeyupTimer && clearTimeout(this.searchKeyupTimer), this.searchKeyupTimer = setTimeout(() => {
      this.doFilter(), this.searchKeyupTimer = null;
    }, tt.SEARCH_DEBOUNCE_MS);
  }
  handleSearchClear() {
    this.searchInput.value = "", this.searchInput.focus(), this.doFilter();
  }
  //* Check if an element is visible within it's container, else scroll until it is.
  scrollTo(t) {
    const e = this.countryList, s = document.documentElement.scrollTop, i = e.offsetHeight, n = e.getBoundingClientRect().top + s, o = n + i, l = t.offsetHeight, a = t.getBoundingClientRect().top + s, c = a + l, d = a - n + e.scrollTop;
    if (a < n)
      e.scrollTop = d;
    else if (c > o) {
      const f = i - l;
      e.scrollTop = d - f;
    }
  }
  //* Remove highlighting from the previous list item and highlight the new one.
  highlightListItem(t, e) {
    const s = this.highlightedItem;
    if (s && s.classList.remove(h.HIGHLIGHT), this.highlightedItem = t, this.highlightedItem && (this.highlightedItem.classList.add(h.HIGHLIGHT), this.options.countrySearch)) {
      const i = this.highlightedItem.getAttribute("id") || "";
      this.searchInput.setAttribute(p.ACTIVE_DESCENDANT, i);
    }
    e && this.highlightedItem.focus();
  }
  //* Highlight the next/prev item in the list (and ensure it is visible).
  handleUpDownKey(t) {
    var s, i;
    let e = t === g.ARROW_UP ? (s = this.highlightedItem) == null ? void 0 : s.previousElementSibling : (i = this.highlightedItem) == null ? void 0 : i.nextElementSibling;
    !e && this.countryList.childElementCount > 1 && (e = t === g.ARROW_UP ? this.countryList.lastElementChild : this.countryList.firstElementChild), e && (this.scrollTo(e), this.highlightListItem(e, !1));
  }
  // Update the selected list item in the dropdown
  updateSelectedItem(t) {
    var e;
    if (this.selectedItem && this.selectedItem.dataset.countryCode !== t && (this.selectedItem.setAttribute(p.SELECTED, "false"), (e = this.selectedItem.querySelector(".iti__country-check")) == null || e.remove(), this.selectedItem = null), t && !this.selectedItem) {
      const s = this.countryList.querySelector(
        `[data-country-code="${t}"]`
      );
      if (s) {
        s.setAttribute(p.SELECTED, "true");
        const i = C(
          "span",
          { class: "iti__country-check", [p.HIDDEN]: "true" },
          s
        );
        i.innerHTML = wt(), this.selectedItem = s;
      }
    }
  }
  //* Country search: Filter the country list to the given array of countries.
  filterCountries(t) {
    this.countryList.innerHTML = "";
    let e = !0;
    for (const s of t) {
      const i = s.nodeById[this.id];
      i && (this.countryList.appendChild(i), e && (this.highlightListItem(i, !1), e = !1));
    }
    e ? (this.highlightListItem(null, !1), this.searchNoResults && this.searchNoResults.classList.remove(h.HIDE)) : this.searchNoResults && this.searchNoResults.classList.add(h.HIDE), this.countryList.scrollTop = 0, this.updateSearchResultsA11yText();
  }
  destroy() {
    this.telInput.iti = void 0, delete this.telInput.dataset.intlTelInputId, this.options.separateDialCode && (this.telInput.style.paddingLeft = this.originalPaddingLeft);
    const t = this.telInput.parentNode;
    t.before(this.telInput), t.remove(), this.telInput = null, this.countryContainer = null, this.selectedCountry = null, this.selectedCountryInner = null, this.selectedDialCode = null, this.dropdownArrow = null, this.dropdownContent = null, this.searchInput = null, this.searchIcon = null, this.searchClearButton = null, this.searchNoResults = null, this.searchResultsA11yText = null, this.countryList = null, this.dropdownForContainer = null, this.hiddenInput = null, this.hiddenInputCountry = null, this.highlightedItem = null, this.selectedItem = null;
    for (const e of this.countries)
      delete e.nodeById[this.id];
    this.countries = null;
  }
  // UI: Open the dropdown (DOM only).
  openDropdown() {
    const {
      countrySearch: t,
      dropdownAlwaysOpen: e,
      dropdownContainer: s
    } = this.options;
    if (this._maybeEnsureDropdownWidthSet(), s)
      this._handleDropdownContainer();
    else {
      const i = this._shouldPositionInlineDropdownBelowInput(), n = this.telInput.offsetHeight + T.DROPDOWN_MARGIN;
      i ? this.dropdownContent.style.top = `${n}px` : this.dropdownContent.style.bottom = `${n}px`;
    }
    if (this.dropdownContent.classList.remove(h.HIDE), this.selectedCountry.setAttribute(p.EXPANDED, "true"), t) {
      const i = this.countryList.firstElementChild;
      i && (this.highlightListItem(i, !1), this.countryList.scrollTop = 0), e || this.searchInput.focus();
    }
    this.dropdownArrow.classList.add(h.ARROW_UP);
  }
  // UI: Close the dropdown (DOM only).
  closeDropdown() {
    const { countrySearch: t, dropdownContainer: e } = this.options;
    this.dropdownContent.classList.add(h.HIDE), this.selectedCountry.setAttribute(p.EXPANDED, "false"), t && (this.searchInput.removeAttribute(p.ACTIVE_DESCENDANT), this.highlightedItem && (this.highlightedItem.classList.remove(h.HIGHLIGHT), this.highlightedItem = null)), this.dropdownArrow.classList.remove(h.ARROW_UP), e ? (this.dropdownForContainer.remove(), this.dropdownForContainer.style.top = "", this.dropdownForContainer.style.bottom = "") : (this.dropdownContent.style.top = "", this.dropdownContent.style.bottom = "");
  }
  _shouldPositionInlineDropdownBelowInput() {
    const t = this.telInput.getBoundingClientRect(), e = t.top, s = window.innerHeight - t.bottom;
    return s >= this.inlineDropdownHeight || s >= e;
  }
  // inject dropdown into container and apply positioning styles
  _handleDropdownContainer() {
    const { dropdownContainer: t, useFullscreenPopup: e } = this.options;
    if (t) {
      if (!e) {
        const s = this.telInput.getBoundingClientRect();
        this.dropdownForContainer.style.left = `${s.left}px`, this._shouldPositionInlineDropdownBelowInput() ? this.dropdownForContainer.style.top = `${s.bottom + T.DROPDOWN_MARGIN}px` : (this.dropdownForContainer.style.top = "unset", this.dropdownForContainer.style.bottom = `${window.innerHeight - s.top + T.DROPDOWN_MARGIN}px`);
      }
      t.appendChild(this.dropdownForContainer);
    }
  }
  // UI: Whether the dropdown is currently closed (hidden).
  isDropdownClosed() {
    return this.dropdownContent.classList.contains(h.HIDE);
  }
  setCountry(t) {
    const { allowDropdown: e, showFlags: s, separateDialCode: i, i18n: n } = this.options, { name: o, dialCode: l, iso2: a = "" } = t;
    if (e && this.updateSelectedItem(a), this.selectedCountry) {
      const c = a && s ? `${h.FLAG} iti__${a}` : `${h.FLAG} ${h.GLOBE}`;
      let d, f, I;
      a ? (f = o, d = n.selectedCountryAriaLabel.replace("${countryName}", o).replace("${dialCode}", `+${l}`), I = s ? "" : X()) : (f = n.noCountrySelected, d = n.noCountrySelected, I = X()), this.selectedCountryInner.className = c, this.selectedCountry.setAttribute("title", f), this.selectedCountry.setAttribute(p.LABEL, d), this.selectedCountryInner.innerHTML = I;
    }
    if (i) {
      const c = l ? `+${l}` : "";
      this.selectedDialCode.textContent = c, this.updateInputPadding();
    }
  }
}
const Dt = (r) => {
  const { onlyCountries: t, excludeCountries: e } = r;
  if (t != null && t.length) {
    const s = t.map(
      (i) => i.toLowerCase()
    );
    return S.filter(
      (i) => s.includes(i.iso2)
    );
  } else if (e != null && e.length) {
    const s = e.map(
      (i) => i.toLowerCase()
    );
    return S.filter(
      (i) => !s.includes(i.iso2)
    );
  }
  return S;
}, Nt = (r, t) => {
  const { countryNameLocale: e, i18n: s } = t;
  let i;
  try {
    typeof Intl < "u" && typeof Intl.DisplayNames == "function" ? i = new Intl.DisplayNames(e, {
      type: "region"
    }) : i = null;
  } catch (n) {
    console.error(n), i = null;
  }
  for (const n of r)
    n.name = s[n.iso2] || (i == null ? void 0 : i.of(n.iso2.toUpperCase())) || "";
}, Et = (r) => {
  const t = /* @__PURE__ */ new Set();
  let e = 0;
  const s = {}, i = (o, l) => {
    if (!o || !l)
      return;
    l.length > e && (e = l.length), s.hasOwnProperty(l) || (s[l] = []);
    const a = s[l];
    a.includes(o) || a.push(o);
  }, n = [...r].sort((o, l) => o.priority - l.priority);
  for (const o of n) {
    t.has(o.dialCode) || t.add(o.dialCode);
    for (let l = 1; l < o.dialCode.length; l++) {
      const a = o.dialCode.substring(0, l);
      i(o.iso2, a);
    }
    if (i(o.iso2, o.dialCode), o.areaCodes) {
      const l = s[o.dialCode][0];
      for (const a of o.areaCodes) {
        for (let c = 1; c < a.length; c++) {
          const d = a.substring(0, c), f = o.dialCode + d;
          i(l, f), i(o.iso2, f);
        }
        i(o.iso2, o.dialCode + a);
      }
    }
  }
  return { dialCodes: t, dialCodeMaxLen: e, dialCodeToIso2Map: s };
}, Lt = (r, t) => {
  t.countryOrder && (t.countryOrder = t.countryOrder.map(
    (e) => e.toLowerCase()
  )), r.sort((e, s) => {
    const { countryOrder: i } = t;
    if (i) {
      const n = i.indexOf(e.iso2), o = i.indexOf(s.iso2), l = n > -1, a = o > -1;
      if (l || a)
        return l && a ? n - o : l ? -1 : 1;
    }
    return e.name.localeCompare(s.name);
  });
}, At = (r) => {
  for (const t of r)
    t.normalisedName = nt(t.name), t.initials = t.normalisedName.split(/[^a-z]/).map((e) => e[0]).join(""), t.dialCodePlus = `+${t.dialCode}`;
}, Tt = /* @__PURE__ */ new Set([
  "800",
  "808",
  "870",
  "881",
  "882",
  "883",
  "888",
  "979"
]), Q = (r) => {
  const t = O(r).slice(0, 3);
  return r.startsWith("+") && Tt.has(t);
}, J = (r, t, e, s) => {
  let i = r;
  if (e && t) {
    const n = `+${s.dialCode}`, o = i[n.length] === " " || i[n.length] === "-" ? n.length + 1 : n.length;
    i = i.substring(o);
  }
  return i;
}, St = (r, t, e, s, i) => {
  const n = e ? e.formatNumberAsYouType(r, s.iso2) : r, { dialCode: o } = s;
  return i && t.charAt(0) !== "+" && n.includes(`+${o}`) ? (n.split(`+${o}`)[1] || "").trim() : n;
}, Pt = (r, t, e, s) => {
  if (e === 0 && !s)
    return 0;
  let i = 0;
  for (let n = 0; n < t.length; n++) {
    if (/[+0-9]/.test(t[n]) && i++, i === r && !s)
      return n + 1;
    if (s && i === r + 1)
      return n;
  }
  return t.length;
}, Ot = [
  "800",
  "822",
  "833",
  "844",
  "855",
  "866",
  "877",
  "880",
  "881",
  "882",
  "883",
  "884",
  "885",
  "886",
  "887",
  "888",
  "889"
], Z = (r) => {
  const t = O(r);
  if (t.startsWith(et.NANP) && t.length >= 4) {
    const e = t.substring(1, 4);
    return Ot.includes(e);
  }
  return !1;
};
class vt {
  constructor() {
  }
  // If any Arabic-Indic digits, then label it as that set. Same for Persian. Otherwise assume ASCII.
  updateNumeralSet(t) {
    /[\u0660-\u0669]/.test(t) ? this.userNumeralSet = "arabic-indic" : /[\u06F0-\u06F9]/.test(t) ? this.userNumeralSet = "persian" : this.userNumeralSet = "ascii";
  }
  // Denormalise ASCII 0-9 to the user's numeral set, if known. If not known, return the string as-is.
  denormalise(t, e) {
    if (this.userNumeralSet || this.updateNumeralSet(e), this.userNumeralSet === "ascii")
      return t;
    const s = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
    return t.replace(/[0-9]/g, (i) => String.fromCharCode(s + Number(i)));
  }
  // Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
  normalise(t) {
    if (!t)
      return "";
    if (this.updateNumeralSet(t), this.userNumeralSet === "ascii")
      return t;
    const e = this.userNumeralSet === "arabic-indic" ? 1632 : 1776, s = this.userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
    return t.replace(s, (i) => String.fromCharCode(48 + (i.charCodeAt(0) - e)));
  }
  isAscii() {
    return this.userNumeralSet === "ascii";
  }
}
let Rt = 0;
const kt = new Set(S.map((r) => r.iso2)), $ = (r) => kt.has(r);
class xt {
  constructor(t, e = {}) {
    this.id = Rt++, R.validateInput(t);
    const s = ft(e);
    this.options = { ...V, ...s }, yt(this.options), this.ui = new R(t, this.options, this.id), this.isAndroid = mt(), this.numerals = new vt(), this.promise = this._createInitPromises(this.options), this.countries = Dt(this.options);
    const { dialCodes: i, dialCodeMaxLen: n, dialCodeToIso2Map: o } = Et(
      this.countries
    );
    this.dialCodes = i, this.dialCodeMaxLen = n, this.dialCodeToIso2Map = o, this.countryByIso2 = new Map(this.countries.map((l) => [l.iso2, l])), this._init();
  }
  _getTelInputValue() {
    const t = this.ui.telInput.value.trim();
    return this.numerals.normalise(t);
  }
  _setTelInputValue(t) {
    const e = this.ui.telInput.value;
    this.ui.telInput.value = this.numerals.denormalise(t, e);
  }
  _createInitPromises(t) {
    const { initialCountry: e, geoIpLookup: s, loadUtils: i } = t, n = e === P.AUTO && !!s, o = !!i && !u.utils;
    let l;
    n ? l = new Promise((c, d) => {
      this.resolveAutoCountryPromise = c, this.rejectAutoCountryPromise = d;
    }) : (l = Promise.resolve(void 0), this.resolveAutoCountryPromise = () => {
    }, this.rejectAutoCountryPromise = () => {
    });
    let a;
    return o ? a = new Promise((c, d) => {
      this.resolveUtilsScriptPromise = c, this.rejectUtilsScriptPromise = d;
    }) : (a = Promise.resolve(void 0), this.resolveUtilsScriptPromise = () => {
    }, this.rejectUtilsScriptPromise = () => {
    }), Promise.all([l, a]);
  }
  //* Can't be private as it's called from intlTelInput convenience wrapper.
  _init() {
    this.selectedCountryData = {}, this.abortController = new AbortController(), this._processCountryData(), this.ui.generateMarkup(this.countries), this._setInitialState(), this._initListeners(), this._initRequests(), this.options.dropdownAlwaysOpen && this._openDropdown();
  }
  //********************
  //*  PRIVATE METHODS
  //********************
  //* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
  _processCountryData() {
    Nt(this.countries, this.options), Lt(this.countries, this.options), At(this.countries);
  }
  //* Set the initial state of the input value and the selected country by:
  //* 1. Extracting a dial code from the given number
  //* 2. Using explicit initialCountry
  _setInitialState(t = !1) {
    const e = this.ui.telInput.getAttribute("value"), s = this.numerals.normalise(e), i = this._getTelInputValue(), o = s && s.startsWith("+") && (!i || !i.startsWith("+")) ? s : i, l = this._getDialCode(o), a = Z(o), { initialCountry: c, geoIpLookup: d } = this.options, I = c === P.AUTO && d && !t, b = c.toLowerCase(), m = $(b);
    l ? a ? m ? this._setCountry(b) : I || this._setCountry(lt.ISO2) : this._updateCountryFromNumber(o) : m ? this._setCountry(b) : I || this._setCountry(""), o && this._updateValFromNumber(o);
  }
  //* Initialise the main event listeners: input keyup, and click selected country.
  _initListeners() {
    this._initTelInputListeners(), this.options.allowDropdown && this._initDropdownListeners(), (this.ui.hiddenInput || this.ui.hiddenInputCountry) && this.ui.telInput.form && this._initHiddenInputListener();
  }
  //* Update hidden input on form submit.
  _initHiddenInputListener() {
    var e;
    const t = () => {
      this.ui.hiddenInput && (this.ui.hiddenInput.value = this.getNumber()), this.ui.hiddenInputCountry && (this.ui.hiddenInputCountry.value = this.selectedCountryData.iso2 || "");
    };
    (e = this.ui.telInput.form) == null || e.addEventListener("submit", t, {
      signal: this.abortController.signal
    });
  }
  //* initialise the dropdown listeners.
  _initDropdownListeners() {
    const t = this.abortController.signal, e = (o) => {
      this.ui.isDropdownClosed() ? this.ui.telInput.focus() : o.preventDefault();
    }, s = this.ui.telInput.closest("label");
    s && s.addEventListener("click", e, { signal: t });
    const i = () => {
      this.ui.isDropdownClosed() && !this.ui.telInput.disabled && !this.ui.telInput.readOnly && this._openDropdown();
    };
    this.ui.selectedCountry.addEventListener(
      "click",
      i,
      {
        signal: t
      }
    );
    const n = (o) => {
      const l = [g.ARROW_UP, g.ARROW_DOWN, g.SPACE, g.ENTER];
      this.ui.isDropdownClosed() && l.includes(o.key) && (o.preventDefault(), o.stopPropagation(), this._openDropdown()), o.key === g.TAB && this._closeDropdown();
    };
    this.ui.countryContainer.addEventListener(
      "keydown",
      n,
      { signal: t }
    );
  }
  //* Init requests: utils script / geo ip lookup.
  _initRequests() {
    const { loadUtils: t, initialCountry: e, geoIpLookup: s } = this.options;
    if (t && !u.utils) {
      const n = () => {
        var o;
        (o = u.attachUtils(t)) == null || o.catch(() => {
        });
      };
      if (u.documentReady())
        n();
      else {
        const o = () => {
          n();
        };
        window.addEventListener("load", o, {
          signal: this.abortController.signal
        });
      }
    } else
      this.resolveUtilsScriptPromise();
    e === P.AUTO && s && (this.selectedCountryData.iso2 ? this.resolveAutoCountryPromise() : this._loadAutoCountry());
  }
  //* Perform the geo ip lookup.
  _loadAutoCountry() {
    if (u.autoCountry)
      this.handleAutoCountry();
    else if (this.ui.selectedCountryInner.classList.add(h.LOADING), !u.startedLoadingAutoCountry && (u.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function")) {
      const t = (s = "") => {
        this.ui.selectedCountryInner.classList.remove(h.LOADING);
        const i = s.toLowerCase();
        $(i) ? (u.autoCountry = i, setTimeout(() => v("handleAutoCountry"))) : v("handleAutoCountryFailure");
      }, e = () => {
        this.ui.selectedCountryInner.classList.remove(h.LOADING), v("handleAutoCountryFailure");
      };
      this.options.geoIpLookup(t, e);
    }
  }
  _openDropdownWithPlus() {
    this._openDropdown(), this.ui.searchInput.value = "+", this.ui.filterCountriesByQuery("");
  }
  //* Initialize the tel input listeners.
  _initTelInputListeners() {
    this._bindInputListener(), this._maybeBindKeydownListener(), this._maybeBindPasteListener();
  }
  _bindInputListener() {
    const {
      strictMode: t,
      formatAsYouType: e,
      separateDialCode: s,
      allowDropdown: i,
      countrySearch: n
    } = this.options;
    let o = !1;
    A.ALPHA_UNICODE.test(this._getTelInputValue()) && (o = !0);
    const l = (a) => {
      const c = this._getTelInputValue();
      if (this.isAndroid && (a == null ? void 0 : a.data) === "+" && s && i && n) {
        const m = this.ui.telInput.selectionStart || 0, N = c.substring(0, m - 1), w = c.substring(m);
        this._setTelInputValue(N + w), this._openDropdownWithPlus();
        return;
      }
      this._updateCountryFromNumber(c) && this._triggerCountryChange();
      const d = (a == null ? void 0 : a.data) && A.NON_PLUS_NUMERIC.test(a.data), f = (a == null ? void 0 : a.inputType) === G.PASTE && c;
      d || f && !t ? o = !0 : A.NON_PLUS_NUMERIC.test(c) || (o = !1);
      const I = (a == null ? void 0 : a.detail) && a.detail.isSetNumber, b = this.numerals.isAscii();
      if (e && !o && !I && b) {
        const m = this.ui.telInput.selectionStart || 0, w = c.substring(
          0,
          m
        ).replace(
          A.NON_PLUS_NUMERIC_GLOBAL,
          ""
        ).length, E = (a == null ? void 0 : a.inputType) === G.DELETE_FWD, y = this._getFullNumber(), L = St(
          y,
          c,
          u.utils,
          this.selectedCountryData,
          s
        ), D = Pt(
          w,
          L,
          m,
          E
        );
        this._setTelInputValue(L), this.ui.telInput.setSelectionRange(D, D);
      }
      if (s && c.startsWith("+") && this.selectedCountryData.dialCode) {
        const m = J(c, !0, s, this.selectedCountryData);
        this._setTelInputValue(m);
      }
    };
    this.ui.telInput.addEventListener(
      "input",
      l,
      {
        signal: this.abortController.signal
      }
    );
  }
  _maybeBindKeydownListener() {
    const { strictMode: t, separateDialCode: e, allowDropdown: s, countrySearch: i } = this.options;
    if (t || e) {
      const n = (o) => {
        if (o.key && o.key.length === 1 && !o.altKey && !o.ctrlKey && !o.metaKey) {
          if (e && s && i && o.key === "+") {
            o.preventDefault(), this._openDropdownWithPlus();
            return;
          }
          if (t) {
            const l = this._getTelInputValue(), c = !l.startsWith("+") && this.ui.telInput.selectionStart === 0 && o.key === "+", d = this.numerals.normalise(o.key), f = /^[0-9]$/.test(d), I = e ? f : c || f, b = this.ui.telInput, m = b.selectionStart, N = b.selectionEnd, w = l.slice(0, m), E = l.slice(N), y = w + o.key + E, L = this._getFullNumber(y), D = u.utils.getCoreNumber(
              L,
              this.selectedCountryData.iso2
            ), M = this.maxCoreNumberLength && D.length > this.maxCoreNumberLength, ot = this._getNewCountryFromNumber(L) !== null;
            (!I || M && !ot && !c) && o.preventDefault();
          }
        }
      };
      this.ui.telInput.addEventListener("keydown", n, {
        signal: this.abortController.signal
      });
    }
  }
  _maybeBindPasteListener() {
    if (this.options.strictMode) {
      const t = (e) => {
        e.preventDefault();
        const s = this.ui.telInput, i = s.selectionStart, n = s.selectionEnd, o = this._getTelInputValue(), l = o.slice(0, i), a = o.slice(n), c = this.selectedCountryData.iso2, d = e.clipboardData.getData("text"), f = this.numerals.normalise(d), I = i === 0 && n > 0, b = !o.startsWith("+") || I, m = f.replace(A.NON_PLUS_NUMERIC_GLOBAL, ""), N = m.startsWith("+"), w = m.replace(/\+/g, ""), E = N && b ? `+${w}` : w;
        let y = l + E + a;
        if (y.length > 5) {
          let D = u.utils.getCoreNumber(y, c);
          for (; D.length === 0 && y.length > 0; )
            y = y.slice(0, -1), D = u.utils.getCoreNumber(y, c);
          if (!D)
            return;
          if (this.maxCoreNumberLength && D.length > this.maxCoreNumberLength)
            if (s.selectionEnd === o.length) {
              const M = D.length - this.maxCoreNumberLength;
              y = y.slice(0, y.length - M);
            } else
              return;
        }
        this._setTelInputValue(y);
        const L = i + E.length;
        s.setSelectionRange(L, L), s.dispatchEvent(new InputEvent("input", { bubbles: !0 }));
      };
      this.ui.telInput.addEventListener("paste", t, {
        signal: this.abortController.signal
      });
    }
  }
  //* Adhere to the input's maxlength attr.
  _cap(t) {
    const e = Number(this.ui.telInput.getAttribute("maxlength"));
    return e && t.length > e ? t.substring(0, e) : t;
  }
  //* Trigger a custom event on the input (typed via ItiEventMap).
  _trigger(t, e = {}) {
    const s = new CustomEvent(t, {
      bubbles: !0,
      cancelable: !0,
      detail: e
    });
    this.ui.telInput.dispatchEvent(s);
  }
  //* Open the dropdown.
  _openDropdown() {
    const { dropdownContainer: t, useFullscreenPopup: e } = this.options;
    if (this.dropdownAbortController = new AbortController(), this.ui.openDropdown(), !e && t) {
      const s = () => this._closeDropdown();
      window.addEventListener("scroll", s, {
        signal: this.dropdownAbortController.signal
      });
    }
    this._bindDropdownListeners(), this._trigger(k.OPEN_COUNTRY_DROPDOWN);
  }
  //* We only bind dropdown listeners when the dropdown is open.
  _bindDropdownListeners() {
    const t = this.dropdownAbortController.signal;
    this._bindDropdownMouseoverListener(t), this._bindDropdownCountryClickListener(t), this.options.dropdownAlwaysOpen || this._bindDropdownClickOffListener(t), this._bindDropdownKeydownListener(t), this.options.countrySearch && this._bindDropdownSearchListeners(t);
  }
  //* When mouse over a list item, just highlight that one
  //* we add the class "highlight", so if they hit "enter" we know which one to select.
  _bindDropdownMouseoverListener(t) {
    const e = (s) => {
      var n;
      const i = (n = s.target) == null ? void 0 : n.closest(
        `.${h.COUNTRY_ITEM}`
      );
      i && this.ui.highlightListItem(i, !1);
    };
    this.ui.countryList.addEventListener(
      "mouseover",
      e,
      {
        signal: t
      }
    );
  }
  //* Listen for country selection.
  _bindDropdownCountryClickListener(t) {
    const e = (s) => {
      var n;
      const i = (n = s.target) == null ? void 0 : n.closest(
        `.${h.COUNTRY_ITEM}`
      );
      i && this._selectListItem(i);
    };
    this.ui.countryList.addEventListener("click", e, {
      signal: t
    });
  }
  //* Click off to close (except when this initial opening click is bubbling up).
  //* We cannot just stopPropagation as it may be needed to close another instance.
  _bindDropdownClickOffListener(t) {
    const e = (s) => {
      !!s.target.closest(
        `#iti-${this.id}__dropdown-content`
      ) || this._closeDropdown();
    };
    setTimeout(() => {
      document.documentElement.addEventListener(
        "click",
        e,
        { signal: t }
      );
    }, 0);
  }
  //* Listen for up/down scrolling, enter to select, or escape to close.
  //* Use keydown as keypress doesn't fire for non-char keys and we want to catch if they
  //* just hit down and hold it to scroll down (no keyup event).
  //* Listen on the document because that's where key events are triggered if no input has focus.
  _bindDropdownKeydownListener(t) {
    let e = "", s = null;
    const i = (n) => {
      [
        g.ARROW_UP,
        g.ARROW_DOWN,
        g.ENTER,
        g.ESC
      ].includes(n.key) && (n.preventDefault(), n.stopPropagation(), n.key === g.ARROW_UP || n.key === g.ARROW_DOWN ? this.ui.handleUpDownKey(n.key) : n.key === g.ENTER ? this._handleEnterKey() : n.key === g.ESC && (this._closeDropdown(), this.ui.selectedCountry.focus())), !this.options.countrySearch && A.HIDDEN_SEARCH_CHAR.test(n.key) && (n.stopPropagation(), s && clearTimeout(s), e += n.key.toLowerCase(), this._searchForCountry(e), s = setTimeout(() => {
        e = "";
      }, tt.HIDDEN_SEARCH_RESET_MS));
    };
    document.addEventListener("keydown", i, { signal: t });
  }
  //* Search input listeners when countrySearch enabled.
  _bindDropdownSearchListeners(t) {
    this.ui.searchInput.addEventListener(
      "input",
      () => this.ui.handleSearchChange(),
      { signal: t }
    ), this.ui.searchClearButton.addEventListener(
      "click",
      () => this.ui.handleSearchClear(),
      { signal: t }
    );
  }
  //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
  _searchForCountry(t) {
    const e = It(this.countries, t);
    if (e) {
      const s = e.nodeById[this.id];
      this.ui.highlightListItem(s, !1), this.ui.scrollTo(s);
    }
  }
  //* Select the currently highlighted item.
  _handleEnterKey() {
    this.ui.highlightedItem && this._selectListItem(this.ui.highlightedItem);
  }
  //* Update the input's value to the given val (format first if possible)
  //* NOTE: this is called from _setInitialState, handleUtils and setNumber.
  _updateValFromNumber(t) {
    const { formatOnDisplay: e, nationalMode: s, separateDialCode: i } = this.options;
    let n = t;
    if (e && u.utils && this.selectedCountryData) {
      const o = Q(t), l = s && !o || !n.startsWith("+") && !i, { NATIONAL: a, INTERNATIONAL: c } = u.utils.numberFormat, d = l ? a : c;
      n = u.utils.formatNumber(
        n,
        this.selectedCountryData.iso2,
        d
      );
    }
    n = this._beforeSetNumber(n), this._setTelInputValue(n);
  }
  //* Check if need to select a new country based on the given number
  //* Note: called from _setInitialState, keyup handler, setNumber.
  _updateCountryFromNumber(t) {
    const e = this._getNewCountryFromNumber(t);
    return e !== null ? this._setCountry(e) : !1;
  }
  // if there is a selected country, and the number doesn't start with a dial code, then add it
  _ensureHasDialCode(t) {
    const { dialCode: e, nationalPrefix: s } = this.selectedCountryData;
    if (t.startsWith("+") || !e)
      return t;
    const o = s && t.startsWith(s) && !this.options.separateDialCode ? t.substring(1) : t;
    return `+${e}${o}`;
  }
  //* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
  _getNewCountryFromNumber(t) {
    const e = t.indexOf("+");
    let s = e ? t.substring(e) : t;
    const i = this.selectedCountryData.iso2, n = this.selectedCountryData.dialCode;
    s = this._ensureHasDialCode(s);
    const o = this._getDialCode(s, !0), l = O(s);
    if (o) {
      const a = O(o), c = this.dialCodeToIso2Map[a];
      if (c.length === 1)
        return c[0] === i ? null : c[0];
      if (!i && this.defaultCountry && c.includes(this.defaultCountry))
        return this.defaultCountry;
      if (n === et.NANP && Z(l))
        return null;
      const { areaCodes: f, priority: I } = this.selectedCountryData;
      if (f) {
        const E = f.map(
          (y) => `${n}${y}`
        );
        for (const y of E)
          if (l.startsWith(y))
            return null;
      }
      const m = f && !(I === 0) && l.length > a.length, N = i && c.includes(i) && !m, w = i === c[0];
      if (!N && !w)
        return c[0];
    } else if (s.startsWith("+") && l.length) {
      const a = this.selectedCountryData.dialCode || "";
      return a && a.startsWith(l) ? null : "";
    } else if ((!s || s === "+") && !i && this.defaultCountry)
      return this.defaultCountry;
    return null;
  }
  //* Update the selected country, dial code (if separateDialCode), placeholder, title, and selected list item.
  //* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
  _setCountry(t) {
    const e = this.selectedCountryData.iso2 || "";
    return this.selectedCountryData = t ? this.countryByIso2.get(t) : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.ui.setCountry(this.selectedCountryData), this._updatePlaceholder(), this._updateMaxLength(), e !== t;
  }
  //* Update the maximum valid number length for the currently selected country.
  _updateMaxLength() {
    const { strictMode: t, placeholderNumberType: e, allowedNumberTypes: s } = this.options, { iso2: i } = this.selectedCountryData;
    if (t && u.utils)
      if (i) {
        const n = u.utils.numberType[e];
        let o = u.utils.getExampleNumber(
          i,
          !1,
          n,
          !0
        ), l = o;
        for (; u.utils.isPossibleNumber(
          o,
          i,
          s
        ); )
          l = o, o += "0";
        const a = u.utils.getCoreNumber(l, i);
        this.maxCoreNumberLength = a.length, i === "by" && (this.maxCoreNumberLength = a.length + 1);
      } else
        this.maxCoreNumberLength = null;
  }
  //* Update the input placeholder to an example number from the currently selected country.
  _updatePlaceholder() {
    const {
      autoPlaceholder: t,
      placeholderNumberType: e,
      nationalMode: s,
      customPlaceholder: i
    } = this.options, n = t === U.AGGRESSIVE || !this.ui.hadInitialPlaceholder && t === U.POLITE;
    if (u.utils && n) {
      const o = u.utils.numberType[e];
      let l = this.selectedCountryData.iso2 ? u.utils.getExampleNumber(
        this.selectedCountryData.iso2,
        s,
        o
      ) : "";
      l = this._beforeSetNumber(l), typeof i == "function" && (l = i(l, this.selectedCountryData)), this.ui.telInput.setAttribute("placeholder", l);
    }
  }
  //* Called when the user selects a list item from the dropdown.
  _selectListItem(t) {
    const e = t.dataset[K.COUNTRY_CODE], s = this._setCountry(e);
    this._closeDropdown();
    const i = t.dataset[K.DIAL_CODE];
    if (this._updateDialCode(i), this.options.formatOnDisplay) {
      const n = this._getTelInputValue();
      this._updateValFromNumber(n);
    }
    this.ui.telInput.focus(), s && this._triggerCountryChange();
  }
  //* Close the dropdown and unbind any listeners.
  _closeDropdown() {
    this.ui.isDropdownClosed() || this.options.dropdownAlwaysOpen || (this.ui.closeDropdown(), this.dropdownAbortController.abort(), this.dropdownAbortController = null, this._trigger(k.CLOSE_COUNTRY_DROPDOWN));
  }
  //* Replace any existing dial code with the new one
  //* Note: called from _selectListItem and setCountry
  _updateDialCode(t) {
    const e = this._getTelInputValue(), s = `+${t}`;
    let i;
    if (e.startsWith("+")) {
      const n = this._getDialCode(e);
      n ? i = e.replace(n, s) : i = s, this._setTelInputValue(i);
    }
  }
  //* Try and extract a valid international dial code from a full telephone number.
  //* Note: returns the raw string inc plus character and any whitespace/dots etc.
  _getDialCode(t, e) {
    let s = "";
    if (t.startsWith("+")) {
      let i = "", n = !1;
      for (let o = 0; o < t.length; o++) {
        const l = t.charAt(o);
        if (/[0-9]/.test(l)) {
          if (i += l, !!!this.dialCodeToIso2Map[i])
            break;
          if (this.dialCodes.has(i)) {
            if (s = t.substring(0, o + 1), n = !0, !e)
              break;
          } else e && n && (s = t.substring(0, o + 1));
          if (i.length === this.dialCodeMaxLen)
            break;
        }
      }
    }
    return s;
  }
  //* Get the input val, adding the dial code if separateDialCode is enabled.
  _getFullNumber(t) {
    const e = t ? this.numerals.normalise(t) : this._getTelInputValue(), { dialCode: s } = this.selectedCountryData;
    let i;
    const n = O(e);
    return this.options.separateDialCode && !e.startsWith("+") && s && n ? i = `+${s}` : i = "", i + e;
  }
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
  _beforeSetNumber(t) {
    const e = !!this._getDialCode(t), s = J(
      t,
      e,
      this.options.separateDialCode,
      this.selectedCountryData
    );
    return this._cap(s);
  }
  //* Trigger the 'countrychange' event.
  _triggerCountryChange() {
    this._trigger(k.COUNTRY_CHANGE);
  }
  //**************************
  //*  SECRET PUBLIC METHODS
  //**************************
  //* This is called when the geoip call returns.
  handleAutoCountry() {
    var t, e;
    if (!((t = this.ui) != null && t.telInput)) {
      (e = this.resolveAutoCountryPromise) == null || e.call(this);
      return;
    }
    this.options.initialCountry === P.AUTO && u.autoCountry && (this.defaultCountry = u.autoCountry, this.selectedCountryData.iso2 || this.ui.selectedCountryInner.classList.contains(h.GLOBE) || this.setCountry(this.defaultCountry), this.resolveAutoCountryPromise());
  }
  //* This is called when the geoip call fails or times out.
  handleAutoCountryFailure() {
    var t, e;
    if (!((t = this.ui) != null && t.telInput)) {
      (e = this.rejectAutoCountryPromise) == null || e.call(this);
      return;
    }
    this._setInitialState(!0), this.rejectAutoCountryPromise();
  }
  //* This is called when the utils request completes.
  handleUtils() {
    var t, e;
    if (!((t = this.ui) != null && t.telInput)) {
      (e = this.resolveUtilsScriptPromise) == null || e.call(this);
      return;
    }
    if (u.utils) {
      const s = this._getTelInputValue();
      s && this._updateValFromNumber(s), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength());
    }
    this.resolveUtilsScriptPromise();
  }
  //* This is called when the utils request fails or times out.
  handleUtilsFailure(t) {
    var e, s;
    if (!((e = this.ui) != null && e.telInput)) {
      (s = this.rejectUtilsScriptPromise) == null || s.call(this, t);
      return;
    }
    this.rejectUtilsScriptPromise(t);
  }
  //********************
  //*  PUBLIC METHODS
  //********************
  //* Remove plugin.
  destroy() {
    this.ui.telInput && (this.options.allowDropdown && this._closeDropdown(), this.abortController.abort(), this.abortController = null, this.ui.destroy(), u.instances instanceof Map ? u.instances.delete(this.id) : delete u.instances[this.id]);
  }
  //* Get the extension from the current number.
  getExtension() {
    return u.utils ? u.utils.getExtension(
      this._getFullNumber(),
      this.selectedCountryData.iso2
    ) : "";
  }
  //* Format the number to the given format.
  getNumber(t) {
    if (u.utils) {
      const { iso2: e } = this.selectedCountryData, s = this._getFullNumber(), i = u.utils.formatNumber(
        s,
        e,
        t
      ), n = this.ui.telInput.value;
      return this.numerals.denormalise(i, n);
    }
    return "";
  }
  //* Get the type of the entered number e.g. landline/mobile.
  getNumberType() {
    return u.utils ? u.utils.getNumberType(
      this._getFullNumber(),
      this.selectedCountryData.iso2
    ) : j.UNKNOWN_NUMBER_TYPE;
  }
  //* Get the country data for the currently selected country.
  getSelectedCountryData() {
    return this.selectedCountryData;
  }
  //* Get the validation error.
  getValidationError() {
    if (u.utils) {
      const { iso2: t } = this.selectedCountryData;
      return u.utils.getValidationError(this._getFullNumber(), t);
    }
    return j.UNKNOWN_VALIDATION_ERROR;
  }
  //* Validate the input val using number length only
  isValidNumber() {
    const { dialCode: t, iso2: e } = this.selectedCountryData;
    if (t === B.DIAL_CODE && u.utils) {
      const s = this._getFullNumber(), i = u.utils.getCoreNumber(s, e);
      if (i[0] === B.MOBILE_PREFIX && i.length !== B.MOBILE_CORE_LENGTH)
        return !1;
    }
    return this._validateNumber(!1);
  }
  //* Validate the input val with precise validation
  isValidNumberPrecise() {
    return this._validateNumber(!0);
  }
  _utilsIsPossibleNumber(t) {
    return u.utils ? u.utils.isPossibleNumber(
      t,
      this.selectedCountryData.iso2,
      this.options.allowedNumberTypes
    ) : null;
  }
  //* Shared internal validation logic to handle alpha character extension rules.
  _validateNumber(t) {
    if (!u.utils)
      return null;
    const { allowNumberExtensions: e, allowPhonewords: s } = this.options, i = (a) => t ? this._utilsIsValidNumber(a) : this._utilsIsPossibleNumber(a), n = this._getFullNumber();
    if (!this.selectedCountryData.iso2 && !Q(n) || !i(n))
      return !1;
    if (n.search(A.ALPHA_UNICODE) > -1) {
      const a = this.selectedCountryData.iso2;
      return u.utils.getExtension(n, a) ? e : s;
    }
    return !0;
  }
  _utilsIsValidNumber(t) {
    return u.utils ? u.utils.isValidNumber(
      t,
      this.selectedCountryData.iso2,
      this.options.allowedNumberTypes
    ) : null;
  }
  //* Update the selected country, and update the input val accordingly.
  setCountry(t) {
    const e = t == null ? void 0 : t.toLowerCase();
    if (!$(e))
      throw new Error(`Invalid country code: '${e}'`);
    const s = this.selectedCountryData.iso2;
    if (t && e !== s || !t && s) {
      if (this._setCountry(e), this._updateDialCode(this.selectedCountryData.dialCode), this.options.formatOnDisplay) {
        const n = this._getTelInputValue();
        this._updateValFromNumber(n);
      }
      this._triggerCountryChange();
    }
  }
  //* Set the input value and update the country.
  setNumber(t) {
    const e = this.numerals.normalise(t), s = this._updateCountryFromNumber(e);
    this._updateValFromNumber(e), s && this._triggerCountryChange(), this._trigger(k.INPUT, { isSetNumber: !0 });
  }
  //* Set the placeholder number typ
  setPlaceholderNumberType(t) {
    this.options.placeholderNumberType = t, this._updatePlaceholder();
  }
  setDisabled(t) {
    this.ui.telInput.disabled = t, t ? this.ui.selectedCountry.setAttribute("disabled", "true") : this.ui.selectedCountry.removeAttribute("disabled");
  }
}
const Ut = (r) => {
  if (!u.utils && !u.startedLoadingUtilsScript) {
    let t;
    if (typeof r == "function")
      try {
        t = Promise.resolve(r());
      } catch (e) {
        return Promise.reject(e);
      }
    else
      return Promise.reject(
        new TypeError(
          `The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof r}`
        )
      );
    return u.startedLoadingUtilsScript = !0, t.then((e) => {
      const s = e == null ? void 0 : e.default;
      if (!s || typeof s != "object")
        throw new TypeError(
          "The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
        );
      return u.utils = s, v("handleUtils"), !0;
    }).catch((e) => {
      throw v("handleUtilsFailure", e), e;
    });
  }
  return null;
}, v = (r, ...t) => {
  Object.values(u.instances).forEach((e) => {
    const s = e[r];
    typeof s == "function" && s.apply(e, t);
  });
}, u = Object.assign(
  (r, t) => {
    const e = new xt(r, t);
    return u.instances[e.id] = e, r.iti = e, e;
  },
  {
    defaults: V,
    //* Using a static var like this allows us to mock it in the tests.
    documentReady: () => document.readyState === "complete",
    //* Get the country data object.
    getCountryData: () => S,
    //* A getter for the plugin instance.
    getInstance: (r) => {
      const t = r.dataset.intlTelInputId;
      return t ? u.instances[t] : null;
    },
    //* A map from instance ID to instance object.
    instances: {},
    attachUtils: Ut,
    startedLoadingUtilsScript: !1,
    startedLoadingAutoCountry: !1,
    version: "26.7.2"
  }
);
export {
  u as i
};
