import i from "../utils.mjs";
import d from "../helpers/parseHeaders.mjs";
const h = Symbol("internals");
function u(o) {
  return o && String(o).trim().toLowerCase();
}
function y(o) {
  return o === !1 || o == null ? o : i.isArray(o) ? o.map(y) : String(o);
}
function S(o) {
  const t = /* @__PURE__ */ Object.create(null), n = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
  let s;
  for (; s = n.exec(o); )
    t[s[1]] = s[2];
  return t;
}
const A = (o) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(o.trim());
function b(o, t, n, s, e) {
  if (i.isFunction(s))
    return s.call(this, t, n);
  if (e && (t = n), !!i.isString(t)) {
    if (i.isString(s))
      return t.indexOf(s) !== -1;
    if (i.isRegExp(s))
      return s.test(t);
  }
}
function E(o) {
  return o.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (t, n, s) => n.toUpperCase() + s);
}
function H(o, t) {
  const n = i.toCamelCase(" " + t);
  ["get", "set", "has"].forEach((s) => {
    Object.defineProperty(o, s + n, {
      value: function(e, r, c) {
        return this[s].call(this, t, e, r, c);
      },
      configurable: !0
    });
  });
}
class g {
  constructor(t) {
    t && this.set(t);
  }
  set(t, n, s) {
    const e = this;
    function r(f, l, a) {
      const m = u(l);
      if (!m)
        throw new Error("header name must be a non-empty string");
      const p = i.findKey(e, m);
      (!p || e[p] === void 0 || a === !0 || a === void 0 && e[p] !== !1) && (e[p || l] = y(f));
    }
    const c = (f, l) => i.forEach(f, (a, m) => r(a, m, l));
    return i.isPlainObject(t) || t instanceof this.constructor ? c(t, n) : i.isString(t) && (t = t.trim()) && !A(t) ? c(d(t), n) : t != null && r(n, t, s), this;
  }
  get(t, n) {
    if (t = u(t), t) {
      const s = i.findKey(this, t);
      if (s) {
        const e = this[s];
        if (!n)
          return e;
        if (n === !0)
          return S(e);
        if (i.isFunction(n))
          return n.call(this, e, s);
        if (i.isRegExp(n))
          return n.exec(e);
        throw new TypeError("parser must be boolean|regexp|function");
      }
    }
  }
  has(t, n) {
    if (t = u(t), t) {
      const s = i.findKey(this, t);
      return !!(s && this[s] !== void 0 && (!n || b(this, this[s], s, n)));
    }
    return !1;
  }
  delete(t, n) {
    const s = this;
    let e = !1;
    function r(c) {
      if (c = u(c), c) {
        const f = i.findKey(s, c);
        f && (!n || b(s, s[f], f, n)) && (delete s[f], e = !0);
      }
    }
    return i.isArray(t) ? t.forEach(r) : r(t), e;
  }
  clear(t) {
    const n = Object.keys(this);
    let s = n.length, e = !1;
    for (; s--; ) {
      const r = n[s];
      (!t || b(this, this[r], r, t, !0)) && (delete this[r], e = !0);
    }
    return e;
  }
  normalize(t) {
    const n = this, s = {};
    return i.forEach(this, (e, r) => {
      const c = i.findKey(s, r);
      if (c) {
        n[c] = y(e), delete n[r];
        return;
      }
      const f = t ? E(r) : String(r).trim();
      f !== r && delete n[r], n[f] = y(e), s[f] = !0;
    }), this;
  }
  concat(...t) {
    return this.constructor.concat(this, ...t);
  }
  toJSON(t) {
    const n = /* @__PURE__ */ Object.create(null);
    return i.forEach(this, (s, e) => {
      s != null && s !== !1 && (n[e] = t && i.isArray(s) ? s.join(", ") : s);
    }), n;
  }
  [Symbol.iterator]() {
    return Object.entries(this.toJSON())[Symbol.iterator]();
  }
  toString() {
    return Object.entries(this.toJSON()).map(([t, n]) => t + ": " + n).join(`
`);
  }
  get [Symbol.toStringTag]() {
    return "AxiosHeaders";
  }
  static from(t) {
    return t instanceof this ? t : new this(t);
  }
  static concat(t, ...n) {
    const s = new this(t);
    return n.forEach((e) => s.set(e)), s;
  }
  static accessor(t) {
    const s = (this[h] = this[h] = {
      accessors: {}
    }).accessors, e = this.prototype;
    function r(c) {
      const f = u(c);
      s[f] || (H(e, c), s[f] = !0);
    }
    return i.isArray(t) ? t.forEach(r) : r(t), this;
  }
}
g.accessor(["Content-Type", "Content-Length", "Accept", "Accept-Encoding", "User-Agent", "Authorization"]);
i.reduceDescriptors(g.prototype, ({ value: o }, t) => {
  let n = t[0].toUpperCase() + t.slice(1);
  return {
    get: () => o,
    set(s) {
      this[n] = s;
    }
  };
});
i.freezeMethods(g);
const k = g;
export {
  k as default
};
