const k = /^xn--/, B = /[^\0-\x7F]/, S = /[\x2E\u3002\uFF0E\uFF61]/g, T = {
  overflow: "Overflow: input needs wider integers to process",
  "not-basic": "Illegal input >= 0x80 (not a basic code point)",
  "invalid-input": "Invalid input"
}, C = 35, l = Math.floor, g = String.fromCharCode;
function d(t) {
  throw new RangeError(T[t]);
}
function D(t, n) {
  const o = [];
  let e = t.length;
  for (; e--; )
    o[e] = n(t[e]);
  return o;
}
function I(t, n) {
  const o = t.split("@");
  let e = "";
  o.length > 1 && (e = o[0] + "@", t = o[1]), t = t.replace(S, ".");
  const s = t.split("."), i = D(s, n).join(".");
  return e + i;
}
function M(t) {
  const n = [];
  let o = 0;
  const e = t.length;
  for (; o < e; ) {
    const s = t.charCodeAt(o++);
    if (s >= 55296 && s <= 56319 && o < e) {
      const i = t.charCodeAt(o++);
      (i & 64512) == 56320 ? n.push(((s & 1023) << 10) + (i & 1023) + 65536) : (n.push(s), o--);
    } else
      n.push(s);
  }
  return n;
}
const E = (t) => String.fromCodePoint(...t), L = function(t) {
  return t >= 48 && t < 58 ? 26 + (t - 48) : t >= 65 && t < 91 ? t - 65 : t >= 97 && t < 123 ? t - 97 : 36;
}, m = function(t, n) {
  return t + 22 + 75 * (t < 26) - ((n != 0) << 5);
}, v = function(t, n, o) {
  let e = 0;
  for (t = o ? l(t / 700) : t >> 1, t += l(t / n); t > C * 26 >> 1; e += 36)
    t = l(t / C);
  return l(e + (C + 1) * t / (t + 38));
}, F = function(t) {
  const n = [], o = t.length;
  let e = 0, s = 128, i = 72, u = t.lastIndexOf("-");
  u < 0 && (u = 0);
  for (let c = 0; c < u; ++c)
    t.charCodeAt(c) >= 128 && d("not-basic"), n.push(t.charCodeAt(c));
  for (let c = u > 0 ? u + 1 : 0; c < o; ) {
    const r = e;
    for (let a = 1, f = 36; ; f += 36) {
      c >= o && d("invalid-input");
      const x = L(t.charCodeAt(c++));
      x >= 36 && d("invalid-input"), x > l((2147483647 - e) / a) && d("overflow"), e += x * a;
      const b = f <= i ? 1 : f >= i + 26 ? 26 : f - i;
      if (x < b)
        break;
      const p = 36 - b;
      a > l(2147483647 / p) && d("overflow"), a *= p;
    }
    const h = n.length + 1;
    i = v(e - r, h, r == 0), l(e / h) > 2147483647 - s && d("overflow"), s += l(e / h), e %= h, n.splice(e++, 0, s);
  }
  return String.fromCodePoint(...n);
}, A = function(t) {
  const n = [];
  t = M(t);
  const o = t.length;
  let e = 128, s = 0, i = 72;
  for (const r of t)
    r < 128 && n.push(g(r));
  const u = n.length;
  let c = u;
  for (u && n.push("-"); c < o; ) {
    let r = 2147483647;
    for (const a of t)
      a >= e && a < r && (r = a);
    const h = c + 1;
    r - e > l((2147483647 - s) / h) && d("overflow"), s += (r - e) * h, e = r;
    for (const a of t)
      if (a < e && ++s > 2147483647 && d("overflow"), a === e) {
        let f = s;
        for (let x = 36; ; x += 36) {
          const b = x <= i ? 1 : x >= i + 26 ? 26 : x - i;
          if (f < b)
            break;
          const p = f - b, w = 36 - b;
          n.push(
            g(m(b + p % w, 0))
          ), f = l(p / w);
        }
        n.push(g(m(f, 0))), i = v(s, h, c === u), s = 0, ++c;
      }
    ++s, ++e;
  }
  return n.join("");
}, N = function(t) {
  return I(t, function(n) {
    return k.test(n) ? F(n.slice(4).toLowerCase()) : n;
  });
}, j = function(t) {
  return I(t, function(n) {
    return B.test(n) ? "xn--" + A(n) : n;
  });
}, O = {
  /**
   * A string representing the current Punycode.js version number.
   * @memberOf punycode
   * @type String
   */
  version: "2.3.1",
  /**
   * An object of methods to convert from JavaScript's internal character
   * representation (UCS-2) to Unicode code points, and back.
   * @see <https://mathiasbynens.be/notes/javascript-encoding>
   * @memberOf punycode
   * @type Object
   */
  ucs2: {
    decode: M,
    encode: E
  },
  decode: F,
  encode: A,
  toASCII: j,
  toUnicode: N
};
export {
  F as decode,
  O as default,
  A as encode,
  j as toASCII,
  N as toUnicode,
  M as ucs2decode,
  E as ucs2encode
};
