import { __module as v } from "./index-_virtual33.js";
import { __require as O } from "./index-window2.js";
import { __require as j } from "./index-extends2.js";
import { __require as S } from "./index-is-function.js";
import { __require as F } from "./index-http-handler.js";
var L;
function G() {
  if (L) return v.exports;
  L = 1;
  var w = O(), _ = j(), g = S();
  s.httpHandler = F();
  var M = function(n) {
    var t = {};
    return n && n.trim().split(`
`).forEach(function(u) {
      var l = u.indexOf(":"), i = u.slice(0, l).trim().toLowerCase(), d = u.slice(l + 1).trim();
      typeof t[i] > "u" ? t[i] = d : Array.isArray(t[i]) ? t[i].push(d) : t[i] = [t[i], d];
    }), t;
  };
  v.exports = s, v.exports.default = s, s.XMLHttpRequest = w.XMLHttpRequest || k, s.XDomainRequest = "withCredentials" in new s.XMLHttpRequest() ? s.XMLHttpRequest : w.XDomainRequest, C(["get", "put", "post", "patch", "head", "delete"], function(e) {
    s[e === "delete" ? "del" : e] = function(n, t, u) {
      return t = H(n, t, u), t.method = e.toUpperCase(), X(t);
    };
  });
  function C(e, n) {
    for (var t = 0; t < e.length; t++)
      n(e[t]);
  }
  function A(e) {
    for (var n in e)
      if (e.hasOwnProperty(n)) return !1;
    return !0;
  }
  function H(e, n, t) {
    var u = e;
    return g(n) ? (t = n, typeof e == "string" && (u = {
      uri: e
    })) : u = _({}, n, {
      uri: e
    }), u.callback = t, u;
  }
  function s(e, n, t) {
    return n = H(e, n, t), X(n);
  }
  function X(e) {
    if (typeof e.callback > "u")
      throw new Error("callback argument missing");
    var n = !1, t = function(o, y, x) {
      n || (n = !0, e.callback(o, y, x));
    };
    function u() {
      r.readyState === 4 && setTimeout(d, 0);
    }
    function l() {
      var a = void 0;
      if (r.response ? a = r.response : a = r.responseText || D(r), E)
        try {
          a = JSON.parse(a);
        } catch {
        }
      return a;
    }
    function i(a) {
      return clearTimeout(b), a instanceof Error || (a = new Error("" + (a || "Unknown XMLHttpRequest Error"))), a.statusCode = 0, t(a, T);
    }
    function d() {
      if (!p) {
        var a;
        clearTimeout(b), e.useXDR && r.status === void 0 ? a = 200 : a = r.status === 1223 ? 204 : r.status;
        var o = T, y = null;
        return a !== 0 ? (o = {
          body: l(),
          statusCode: a,
          method: c,
          headers: {},
          url: h,
          rawRequest: r
        }, r.getAllResponseHeaders && (o.headers = M(r.getAllResponseHeaders()))) : y = new Error("Internal XMLHttpRequest Error"), t(y, o, o.body);
      }
    }
    var r = e.xhr || null;
    r || (e.cors || e.useXDR ? r = new s.XDomainRequest() : r = new s.XMLHttpRequest());
    var m, p, h = r.url = e.uri || e.url, c = r.method = e.method || "GET", q = e.body || e.data, f = r.headers = e.headers || {}, R = !!e.sync, E = !1, b, T = {
      body: void 0,
      headers: {},
      statusCode: 0,
      method: c,
      url: h,
      rawRequest: r
    };
    if ("json" in e && e.json !== !1 && (E = !0, f.accept || f.Accept || (f.Accept = "application/json"), c !== "GET" && c !== "HEAD" && (f["content-type"] || f["Content-Type"] || (f["Content-Type"] = "application/json"), q = JSON.stringify(e.json === !0 ? q : e.json))), r.onreadystatechange = u, r.onload = d, r.onerror = i, r.onprogress = function() {
    }, r.onabort = function() {
      p = !0;
    }, r.ontimeout = i, r.open(c, h, !R, e.username, e.password), R || (r.withCredentials = !!e.withCredentials), !R && e.timeout > 0 && (b = setTimeout(function() {
      if (!p) {
        p = !0, r.abort("timeout");
        var a = new Error("XMLHttpRequest timeout");
        a.code = "ETIMEDOUT", i(a);
      }
    }, e.timeout)), r.setRequestHeader)
      for (m in f)
        f.hasOwnProperty(m) && r.setRequestHeader(m, f[m]);
    else if (e.headers && !A(e.headers))
      throw new Error("Headers cannot be set on an XDomainRequest object");
    return "responseType" in e && (r.responseType = e.responseType), "beforeSend" in e && typeof e.beforeSend == "function" && e.beforeSend(r), r.send(q || null), r;
  }
  function D(e) {
    try {
      if (e.responseType === "document")
        return e.responseXML;
      var n = e.responseXML && e.responseXML.documentElement.nodeName === "parsererror";
      if (e.responseType === "" && !n)
        return e.responseXML;
    } catch {
    }
    return null;
  }
  function k() {
  }
  return v.exports;
}
export {
  G as __require
};
