(function (g) {
'use strict';
/** Central allowlist — host part only (lowercase). */
const ALLOWED_EMAIL_DOMAIN_LIST = [
  'gmail.com',
  'googlemail.com',
  'outlook.com',
  'hotmail.com',
  'live.com',
  'msn.com',
  'yahoo.com',
  'ymail.com',
  'rocketmail.com',
  'icloud.com',
  'me.com',
  'mac.com',
  'proton.me',
  'protonmail.com',
  'pm.me',
  'tutanota.com',
  'tuta.com',
  'mail.com',
  'email.com',
  'gmx.com',
  'gmx.net',
  'gmx.de',
  'gmx.at',
  'gmx.ch',
  'aol.com',
  'zoho.com',
  'fastmail.com',
  'hey.com',
  'hushmail.com',
  'mailfence.com',
  'runbox.com',
  'startmail.com',
  'posteo.de',
  'mailbox.org',
  'disroot.org',
  'riseup.net',
  'cock.li',
  'ctemplar.com',
  'lavabit.com',
  'mail.ru',
  'bk.ru',
  'inbox.ru',
  'list.ru',
  'yandex.ru',
  'yandex.com',
  'yandex.kz',
  'yandex.ua',
  'yandex.by',
  'ya.ru',
  'rambler.ru',
  'ukr.net',
  'i.ua',
  'meta.ua',
  'bigmir.net',
  'online.ua',
  'email.ua',
  'voliacable.com',
  'freemail.hu',
  'seznam.cz',
  'centrum.cz',
  'atlas.cz',
  'post.cz',
  'azet.sk',
  'pobox.sk',
  'onet.pl',
  'wp.pl',
  'interia.pl',
  'o2.pl',
  'gazeta.pl',
  'qq.com',
  '163.com',
  '126.com',
  'yeah.net',
  'sina.com',
  'sohu.com',
  'foxmail.com',
  'aliyun.com',
  '139.com',
  '189.cn',
  '21cn.com',
  'naver.com',
  'daum.net',
  'hanmail.net',
  'kakao.com',
  'nate.com',
  'rediffmail.com',
  'indiatimes.com',
  'sify.com',
  'mail.ee',
  'orange.fr',
  'wanadoo.fr',
  'laposte.net',
  'free.fr',
  'sfr.fr',
  'neuf.fr',
  'bbox.fr',
  'libero.it',
  'virgilio.it',
  'alice.it',
  'tin.it',
  'tiscali.it',
  'email.it',
  'web.de',
  't-online.de',
  'freenet.de',
  'arcor.de',
  'bluewin.ch',
  'hispeed.ch',
  'mail.ch',
  'chello.at',
  'abv.bg',
  'dir.bg',
  'mail.bg',
  'terra.com',
  'terra.com.br',
  'uol.com.br',
  'bol.com.br',
  'ig.com.br',
  'globo.com',
  'r7.com',
  'zipmail.com.br',
  'outlook.com.br',
  'yahoo.com.br',
  'comcast.net',
  'verizon.net',
  'att.net',
  'sbcglobal.net',
  'bellsouth.net',
  'cox.net',
  'charter.net',
  'spectrum.net',
  'earthlink.net',
  'frontier.com',
  'frontiernet.net',
  'optimum.net',
  'optonline.net',
  'shaw.ca',
  'rogers.com',
  'sympatico.ca',
  'telus.net',
  'bell.net',
  'xtra.co.nz',
  'bigpond.com',
  'bigpond.net.au',
  'optusnet.com.au',
  'iinet.net.au',
  'btinternet.com',
  'btopenworld.com',
  'talktalk.net',
  'sky.com',
  'virginmedia.com',
  'ntlworld.com',
  'blueyonder.co.uk',
  'tiscali.co.uk',
  'usa.com',
  'consultant.com',
  'engineer.com',
  'accountant.com',
  'doctor.com',
  'lawyer.com',
  'techie.com',
  'programmer.net',
  'dr.com',
  'outlook.co.uk',
  'outlook.fr',
  'outlook.de',
  'outlook.es',
  'outlook.it',
  'outlook.jp',
  'hotmail.co.uk',
  'hotmail.fr',
  'hotmail.de',
  'hotmail.es',
  'hotmail.it',
  'live.co.uk',
  'live.fr',
  'live.de',
  'yahoo.co.uk',
  'yahoo.co.jp',
  'yahoo.de',
  'yahoo.fr',
  'yahoo.com.br'
];

const ALLOWED_DOMAINS = new Set(ALLOWED_EMAIL_DOMAIN_LIST);

/** Exact host -> display provider name */
const PROVIDER_BY_HOST = {
  'gmail.com': 'Gmail',
  'googlemail.com': 'Gmail',
  'outlook.com': 'Outlook',
  'hotmail.com': 'Outlook',
  'live.com': 'Outlook',
  'msn.com': 'Outlook',
  'outlook.com.br': 'Outlook',
  'outlook.co.uk': 'Outlook',
  'outlook.fr': 'Outlook',
  'outlook.de': 'Outlook',
  'outlook.es': 'Outlook',
  'outlook.it': 'Outlook',
  'outlook.jp': 'Outlook',
  'hotmail.co.uk': 'Outlook',
  'hotmail.fr': 'Outlook',
  'hotmail.de': 'Outlook',
  'hotmail.es': 'Outlook',
  'hotmail.it': 'Outlook',
  'live.co.uk': 'Outlook',
  'live.fr': 'Outlook',
  'live.de': 'Outlook',
  'yahoo.com': 'Yahoo',
  'ymail.com': 'Yahoo',
  'rocketmail.com': 'Yahoo',
  'yahoo.co.uk': 'Yahoo',
  'yahoo.co.jp': 'Yahoo',
  'yahoo.de': 'Yahoo',
  'yahoo.fr': 'Yahoo',
  'yahoo.com.br': 'Yahoo',
  'icloud.com': 'iCloud',
  'me.com': 'iCloud',
  'mac.com': 'iCloud',
  'proton.me': 'Proton',
  'protonmail.com': 'Proton',
  'pm.me': 'Proton',
  'tutanota.com': 'Tutanota',
  'tuta.com': 'Tutanota',
  'gmx.com': 'GMX',
  'gmx.net': 'GMX',
  'gmx.de': 'GMX',
  'gmx.at': 'GMX',
  'gmx.ch': 'GMX',
  'web.de': 'Web.de',
  't-online.de': 'T-Online',
  'qq.com': 'QQ',
  '163.com': '163',
  '126.com': '126',
  'mail.ru': 'Mail.ru',
  'bk.ru': 'Mail.ru',
  'inbox.ru': 'Mail.ru',
  'list.ru': 'Mail.ru',
  'yandex.ru': 'Yandex',
  'yandex.com': 'Yandex',
  'yandex.kz': 'Yandex',
  'yandex.ua': 'Yandex',
  'yandex.by': 'Yandex',
  'ya.ru': 'Yandex',
  'rambler.ru': 'Rambler',
  'ukr.net': 'Ukr.net',
  'bigpond.com': 'Bigpond',
  'bigpond.net.au': 'Bigpond',
  'blueyonder.co.uk': 'Blueyonder'
};

const HOST_PREFIX_PROVIDER = [
  [/^(gmail|googlemail)\./, 'Gmail'],
  [/^(outlook|hotmail|live|msn)\./, 'Outlook'],
  [/^(yahoo|ymail|rocketmail)\./, 'Yahoo'],
  [/^(protonmail|proton|pm)\./, 'Proton'],
  [/^(icloud|me|mac)\./, 'iCloud'],
  [/^gmx\./, 'GMX'],
  [/^(qq|foxmail)\./, 'QQ'],
  [/^(163|126|yeah)\./, 'China Mail'],
  [/^(naver|daum|hanmail|kakao|nate)\./, 'Korean Mail'],
  [/^(mail|bk|inbox|list)\.ru$/, 'Mail.ru'],
  [/^(yandex\.|ya\.ru$)/, 'Yandex'],
  [/^rambler\./, 'Rambler'],
  [/^(ukr|i\.ua|meta|bigmir|online|email)\./, 'Ukrainian Mail'],
  [/^(onet|wp|interia|o2|gazeta)\./, 'Polish Mail'],
  [/^(seznam|centrum|atlas|post)\./, 'Czech Mail'],
  [/^(libero|virgilio|alice|tin|tiscali|email)\./, 'Italian Mail'],
  [/^(orange|wanadoo|laposte|free|sfr|neuf|bbox)\./, 'French Mail'],
  [/^(btinternet|btopenworld|talktalk|sky|virginmedia|ntlworld|blueyonder)\./, 'UK ISP Mail']
];

function getEmailHost(email) {
  const e = String(email || '')
    .toLowerCase()
    .trim();
  const at = e.lastIndexOf('@');
  if (at < 1) return '';
  return e.slice(at + 1);
}

function isAllowedEmailDomain(email) {
  const host = getEmailHost(email);
  return host.length > 0 && ALLOWED_DOMAINS.has(host);
}

function getProviderForHost(host) {
  const h = String(host || '').toLowerCase();
  if (!h) return 'Unknown';
  if (
    /^(redmi|xiaomi|miui|oppo|vivo|realme|oneplus|huawei|honor|iqoo|nothing|tecno|infinix|meizu|zte)(\.|$)/i.test(
      h
    )
  ) {
    return 'Other';
  }
  if (PROVIDER_BY_HOST[h]) return PROVIDER_BY_HOST[h];
  for (const [re, name] of HOST_PREFIX_PROVIDER) {
    if (re.test(h)) return name;
  }
  const base = h.split('.')[0] || h;
  return base.charAt(0).toUpperCase() + base.slice(1);
}

function getEmailProvider(email) {
  return getProviderForHost(getEmailHost(email));
}


g.RbxEmailDomains = {
  ALLOWED_DOMAINS: ALLOWED_DOMAINS,
  getEmailHost: getEmailHost,
  isAllowedEmailDomain: isAllowedEmailDomain,
  getProviderForHost: getProviderForHost,
  getEmailProvider: getEmailProvider
};
})(typeof globalThis !== 'undefined' ? globalThis : window);
