import { __module as q } from "../../../../../../../../_virtual/index5.js";
import { __require as F } from "../../../../../global@4.4.0/node_modules/global/window.js";
import { __require as N } from "../../../../../@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/extends.js";
import { __require as J } from "../../../../../is-function@1.0.2/node_modules/is-function/index.js";
import { __require as z } from "./interceptors.js";
import { __require as G } from "./retry.js";
import { __require as B } from "./http-handler.js";
var S;
function P() {
  if (S) return q.exports;
  S = 1;
  var H = F(), x = N(), C = J(), X = z(), A = G();
  a.httpHandler = B(), a.requestInterceptorsStorage = new X(), a.responseInterceptorsStorage = new X(), a.retryManager = new A();
  /**
   * @license
   * slighly modified parse-headers 2.0.2 <https://github.com/kesla/parse-headers/>
   * Copyright (c) 2014 David Björklund
   * Available under the MIT license
   * <https://github.com/kesla/parse-headers/blob/master/LICENCE>
   */
  var D = function(n) {
    var t = {};
    return n && n.trim().split(`
`).forEach(function(u) {
      var l = u.indexOf(":"), c = u.slice(0, l).trim().toLowerCase(), y = u.slice(l + 1).trim();
      typeof t[c] > "u" ? t[c] = y : Array.isArray(t[c]) ? t[c].push(y) : t[c] = [t[c], y];
    }), t;
  };
  q.exports = a, q.exports.default = a, a.XMLHttpRequest = H.XMLHttpRequest || j, a.XDomainRequest = "withCredentials" in new a.XMLHttpRequest() ? a.XMLHttpRequest : H.XDomainRequest, k(["get", "put", "post", "patch", "head", "delete"], function(e) {
    a[e === "delete" ? "del" : e] = function(n, t, u) {
      return t = I(n, t, u), t.method = e.toUpperCase(), b(t);
    };
  });
  function k(e, n) {
    for (var t = 0; t < e.length; t++)
      n(e[t]);
  }
  function O(e) {
    for (var n in e)
      if (e.hasOwnProperty(n)) return !1;
    return !0;
  }
  function I(e, n, t) {
    var u = e;
    return C(n) ? (t = n, typeof e == "string" && (u = {
      uri: e
    })) : u = x({}, n, {
      uri: e
    }), u.callback = t, u;
  }
  function a(e, n, t) {
    return n = I(e, n, t), b(n);
  }
  function b(e) {
    if (typeof e.callback > "u")
      throw new Error("callback argument missing");
    if (e.requestType && a.requestInterceptorsStorage.getIsEnabled()) {
      var n = {
        uri: e.uri || e.url,
        headers: e.headers || {},
        body: e.body,
        metadata: e.metadata || {},
        retry: e.retry,
        timeout: e.timeout
      }, t = a.requestInterceptorsStorage.execute(e.requestType, n);
      e.uri = t.uri, e.headers = t.headers, e.body = t.body, e.metadata = t.metadata, e.retry = t.retry, e.timeout = t.timeout;
    }
    var u = !1, l = function(i, d, E) {
      u || (u = !0, e.callback(i, d, E));
    };
    function c() {
      r.readyState === 4 && !a.responseInterceptorsStorage.getIsEnabled() && setTimeout(L, 0);
    }
    function y() {
      var s = void 0;
      if (r.response ? s = r.response : s = r.responseText || U(r), _)
        try {
          s = JSON.parse(s);
        } catch {
        }
      return s;
    }
    function v(s) {
      if (clearTimeout(w), clearTimeout(e.retryTimeout), s instanceof Error || (s = new Error("" + (s || "Unknown XMLHttpRequest Error"))), s.statusCode = 0, !m && a.retryManager.getIsEnabled() && e.retry && e.retry.shouldRetry()) {
        e.retryTimeout = setTimeout(function() {
          e.retry.moveToNextAttempt(), e.xhr = r, b(e);
        }, e.retry.getCurrentFuzzedDelay());
        return;
      }
      if (e.requestType && a.responseInterceptorsStorage.getIsEnabled()) {
        var i = {
          headers: o.headers || {},
          body: o.body,
          responseUrl: r.responseURL,
          responseType: r.responseType
        }, d = a.responseInterceptorsStorage.execute(e.requestType, i);
        o.body = d.body, o.headers = d.headers;
      }
      return l(s, o);
    }
    function L() {
      if (!m) {
        var s;
        clearTimeout(w), clearTimeout(e.retryTimeout), e.useXDR && r.status === void 0 ? s = 200 : s = r.status === 1223 ? 204 : r.status;
        var i = o, d = null;
        if (s !== 0 ? (i = {
          body: y(),
          statusCode: s,
          method: h,
          headers: {},
          url: T,
          rawRequest: r
        }, r.getAllResponseHeaders && (i.headers = D(r.getAllResponseHeaders()))) : d = new Error("Internal XMLHttpRequest Error"), e.requestType && a.responseInterceptorsStorage.getIsEnabled()) {
          var E = {
            headers: i.headers || {},
            body: i.body,
            responseUrl: r.responseURL,
            responseType: r.responseType
          }, M = a.responseInterceptorsStorage.execute(e.requestType, E);
          i.body = M.body, i.headers = M.headers;
        }
        return l(d, i, i.body);
      }
    }
    var r = e.xhr || null;
    r || (e.cors || e.useXDR ? r = new a.XDomainRequest() : r = new a.XMLHttpRequest());
    var p, m, T = r.url = e.uri || e.url, h = r.method = e.method || "GET", g = e.body || e.data, f = r.headers = e.headers || {}, R = !!e.sync, _ = !1, w, o = {
      body: void 0,
      headers: {},
      statusCode: 0,
      method: h,
      url: T,
      rawRequest: r
    };
    if ("json" in e && e.json !== !1 && (_ = !0, f.accept || f.Accept || (f.Accept = "application/json"), h !== "GET" && h !== "HEAD" && (f["content-type"] || f["Content-Type"] || (f["Content-Type"] = "application/json"), g = JSON.stringify(e.json === !0 ? g : e.json))), r.onreadystatechange = c, r.onload = L, r.onerror = v, r.onprogress = function() {
    }, r.onabort = function() {
      m = !0, clearTimeout(e.retryTimeout);
    }, r.ontimeout = v, r.open(h, T, !R, e.username, e.password), R || (r.withCredentials = !!e.withCredentials), !R && e.timeout > 0 && (w = setTimeout(function() {
      if (!m) {
        m = !0, r.abort("timeout");
        var s = new Error("XMLHttpRequest timeout");
        s.code = "ETIMEDOUT", v(s);
      }
    }, e.timeout)), r.setRequestHeader)
      for (p in f)
        f.hasOwnProperty(p) && r.setRequestHeader(p, f[p]);
    else if (e.headers && !O(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(g || null), r;
  }
  function U(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 j() {
  }
  return q.exports;
}
export {
  P as __require
};
//# sourceMappingURL=index.js.map
