import t from "../utils.mjs";
import p from "../core/AxiosError.mjs";
import u from "./transitional.mjs";
import S from "../helpers/toFormData.mjs";
import h from "../helpers/toURLEncodedForm.mjs";
import l from "../platform/index.mjs";
import O from "../helpers/formDataToJSON.mjs";
function y(i, r, e) {
  if (t.isString(i))
    try {
      return (r || JSON.parse)(i), t.trim(i);
    } catch (n) {
      if (n.name !== "SyntaxError")
        throw n;
    }
  return (e || JSON.stringify)(i);
}
const m = {
  transitional: u,
  adapter: ["xhr", "http"],
  transformRequest: [function(r, e) {
    const n = e.getContentType() || "", o = n.indexOf("application/json") > -1, f = t.isObject(r);
    if (f && t.isHTMLForm(r) && (r = new FormData(r)), t.isFormData(r))
      return o && o ? JSON.stringify(O(r)) : r;
    if (t.isArrayBuffer(r) || t.isBuffer(r) || t.isStream(r) || t.isFile(r) || t.isBlob(r))
      return r;
    if (t.isArrayBufferView(r))
      return r.buffer;
    if (t.isURLSearchParams(r))
      return e.setContentType("application/x-www-form-urlencoded;charset=utf-8", !1), r.toString();
    let s;
    if (f) {
      if (n.indexOf("application/x-www-form-urlencoded") > -1)
        return h(r, this.formSerializer).toString();
      if ((s = t.isFileList(r)) || n.indexOf("multipart/form-data") > -1) {
        const a = this.env && this.env.FormData;
        return S(
          s ? { "files[]": r } : r,
          a && new a(),
          this.formSerializer
        );
      }
    }
    return f || o ? (e.setContentType("application/json", !1), y(r)) : r;
  }],
  transformResponse: [function(r) {
    const e = this.transitional || m.transitional, n = e && e.forcedJSONParsing, o = this.responseType === "json";
    if (r && t.isString(r) && (n && !this.responseType || o)) {
      const c = !(e && e.silentJSONParsing) && o;
      try {
        return JSON.parse(r);
      } catch (s) {
        if (c)
          throw s.name === "SyntaxError" ? p.from(s, p.ERR_BAD_RESPONSE, this, null, this.response) : s;
      }
    }
    return r;
  }],
  /**
   * A timeout in milliseconds to abort a request. If set to 0 (default) a
   * timeout is not created.
   */
  timeout: 0,
  xsrfCookieName: "XSRF-TOKEN",
  xsrfHeaderName: "X-XSRF-TOKEN",
  maxContentLength: -1,
  maxBodyLength: -1,
  env: {
    FormData: l.classes.FormData,
    Blob: l.classes.Blob
  },
  validateStatus: function(r) {
    return r >= 200 && r < 300;
  },
  headers: {
    common: {
      Accept: "application/json, text/plain, */*",
      "Content-Type": void 0
    }
  }
};
t.forEach(["delete", "get", "head", "post", "put", "patch"], (i) => {
  m.headers[i] = {};
});
const T = m;
export {
  T as default
};
