function f(e, r) {
  var s = "cannot ".concat(e.method, " ").concat(e.action, " ").concat(r.status, "'"), n = new Error(s);
  return n.status = r.status, n.method = e.method, n.url = e.action, n;
}
function u(e) {
  var r = e.responseText || e.response;
  if (!r)
    return r;
  try {
    return JSON.parse(r);
  } catch {
    return r;
  }
}
function d(e) {
  var r = new XMLHttpRequest();
  e.onProgress && r.upload && (r.upload.onprogress = function(t) {
    t.total > 0 && (t.percent = t.loaded / t.total * 100), e.onProgress(t);
  });
  var s = new FormData();
  e.data && Object.keys(e.data).forEach(function(a) {
    var t = e.data[a];
    if (Array.isArray(t)) {
      t.forEach(function(c) {
        s.append("".concat(a, "[]"), c);
      });
      return;
    }
    s.append(a, t);
  }), e.file instanceof Blob ? s.append(e.filename, e.file, e.file.name) : s.append(e.filename, e.file), r.onerror = function(t) {
    e.onError(t);
  }, r.onload = function() {
    return r.status < 200 || r.status >= 300 ? e.onError(f(e, r), u(r)) : e.onSuccess(u(r), r);
  }, r.open(e.method, e.action, !0), e.withCredentials && "withCredentials" in r && (r.withCredentials = !0);
  var n = e.headers || {};
  return n["X-Requested-With"] !== null && r.setRequestHeader("X-Requested-With", "XMLHttpRequest"), Object.keys(n).forEach(function(a) {
    n[a] !== null && r.setRequestHeader(a, n[a]);
  }), r.send(s), {
    abort: function() {
      r.abort();
    }
  };
}
export {
  d as default
};
