var d = Object.defineProperty;
var h = (i, t, e) => t in i ? d(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
var f = (i, t, e) => h(i, typeof t != "symbol" ? t + "" : t, e);
import m from "axios";
import { merge as p } from "lodash";
import { SHJParseEvent as c } from "../../event/index.mjs";
import { EventUtils as u } from "../../event/utils/utils.mjs";
class U {
  constructor() {
    f(this, "instance");
    this.instance = m.create(), this.instance.interceptors.response.use((t) => {
      try {
        const e = t.config, r = u.getGlobalEvent(), o = u.getGlobalApiListenter();
        o.length && o.forEach((n) => {
          n.type === "include" && e.url.includes(n.url) && c.parseEvents(
            r,
            "on-global-api-listenter",
            t
          ), n.type === "exclude" && (e.url.includes(n.url) || c.parseEvents(
            r,
            "on-global-api-listenter",
            t
          )), n.type === "equal" && e.url === n.url && c.parseEvents(
            r,
            "on-global-api-listenter",
            t
          ), n.type === "notEqual" && e.url !== n.url && c.parseEvents(
            r,
            "on-global-api-listenter",
            t
          );
        });
      } catch {
      }
      return t;
    });
  }
  /**
   * GET 请求
   * @param url
   * @param config
   * @returns
   */
  get(t, e) {
    return this.instance.get(t, e);
  }
  /**
   * POST 请求
   * @param url 请求的URL
   * @param data 发送的数据
   * @param contentType 数据的内容类型
   * @param config 额外的Axios配置
   * @returns
   */
  post(t, e, r, o = "application/json; charset=UTF-8") {
    const n = {
      headers: {
        "Content-Type": "application/json; charset=UTF-8"
        /* Json */
      }
    };
    if (o === "multipart/form-data") {
      n.headers = {};
      const a = new FormData();
      for (const s in e)
        a.append(s, e[s]);
      e = a;
    } else o === "application/x-www-form-urlencoded; charset=UTF-8" && (n.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8", n.transformRequest = [
      (a) => {
        const s = new URLSearchParams();
        for (const l in a)
          s.append(l, a[l]);
        return s.toString();
      }
    ]);
    return this.instance.post(t, e, p({}, n, r));
  }
  /**
   * PUT 请求
   * @param url
   * @param data
   * @param config
   * @returns
   */
  put(t, e, r, o = "application/x-www-form-urlencoded; charset=UTF-8") {
    const n = {
      headers: {
        "Content-Type": o
      }
    };
    if (o === "multipart/form-data") {
      n.headers = {};
      const a = new FormData();
      for (const s in e)
        a.append(s, e[s]);
      e = a;
    } else o === "application/x-www-form-urlencoded; charset=UTF-8" && (n.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8", n.transformRequest = [
      (a) => {
        const s = new URLSearchParams();
        for (const l in a)
          s.append(l, a[l]);
        return s.toString();
      }
    ]);
    return this.instance.put(t, e, p({}, n, r));
  }
  /**
   * DELETE 请求
   * @param url
   * @param config
   * @returns
   */
  delete(t, e) {
    const r = {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
        /* UrlEncoded */
      }
    };
    return this.instance.delete(t, p({}, r, e));
  }
  /**
   * 文件上传
   * @param url
   * @param params
   * @param config
   * @returns
   */
  upload(t, e, r) {
    const o = {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    };
    return this.instance.post(t, e, r || o);
  }
  /**
   * blob文件下载
   * @param url
   * @param params
   * @param config
   * @returns
   */
  download(t, e, r) {
    const o = {
      responseType: "blob",
      headers: {
        "Content-Type": "application/json"
      }
    };
    return this.instance.post(t, e, r || o);
  }
  /**
   * Custom 请求
   * @param url
   * @param config
   * @returns
   */
  custom(t, e) {
    return this.instance.get(t, e);
  }
}
export {
  U as HttpRequest
};
