import { defineComponent as U, inject as j, ref as H, reactive as N, computed as O, watch as M, onMounted as F, nextTick as J, openBlock as C, createElementBlock as R, normalizeClass as D, createElementVNode as L, normalizeStyle as B, Fragment as v, createBlock as K } from "vue";
import { C as i } from "../Shared/base-PQGakkrl.js";
import "js-cookie";
import "decimal.js";
import { C as P } from "../Shared/index-BnerInzC.js";
import "../Shared/day-Bz9LfelO.js";
import w from "axios";
import A from "qs";
import "echarts";
import "@popperjs/core";
import { _ as $ } from "../Shared/Index.vue_vue_type_script_setup_true_lang-Cuv5NgcY.js";
class I {
  requestPendingList;
  globalOptions;
  constructor() {
    this.requestPendingList = /* @__PURE__ */ new Map(), this.globalOptions = {}, this._setInterceptors();
  }
  _initRequest(e, t, s) {
    const o = this, r = this._getExtInfo(s.ext);
    return new Promise((c) => {
      const a = /* @__PURE__ */ new Date();
      let b = {
        url: e,
        timeout: 1e3 * 15,
        responseType: "json",
        retry: 3,
        retryDelay: 1e3
        //_requestKeyMerge: ["method", "url", "_ran"],
      };
      b = i.getJsonMerge(b, s.options, t), w(b).then((d) => {
        if (s.ext._operateType === "fileDownBinary")
          s.ext.uploadDownBinaryCallback(d, r, c);
        else {
          const m = r.resultCallback ? r.resultCallback(d) : o._initResult(d, r.resultCode);
          o._initRequestResolve(c, m, r, a);
        }
      }).catch((d) => {
        if (r.errorCallback && d.response) {
          const m = r.errorCallback(d);
          m && (m.then && i.isFunction(m.then) ? m.then((p) => {
            o._initRequestError(d, c, p, r, a);
          }) : o._initRequestError(d, c, m, r, a));
        } else {
          let m = "", p = "";
          d.response ? m = d.response.status.toString() : d.code === "ECONNABORTED" ? p = "Axios:TimeOut  Repeat" : i.isEmpty(d.message) || (p = `Axios:${i.isEmpty(d.code) ? "" : d.code + "-"}${d.message}`);
          const y = o._initResultErr(m, p);
          o._initRequestError(d, c, y, r, a);
        }
      });
    });
  }
  _initRequestResolve(e, t, s, o) {
    s.isTimeOut ? this._timeOut(o, () => {
      e(t);
    }) : e(t);
  }
  _initRequestError(e, t, s, o, r) {
    w.isCancel(e) || this._initRequestResolve(t, s, o, r);
  }
  initGet(e) {
    const t = {
      method: "get",
      headers: this._getHeader(e.ext),
      params: e.param
    };
    return this._initRequest(e.url, t, e);
  }
  initPost(e) {
    const t = {
      method: "post",
      headers: this._getHeader(e.ext),
      data: JSON.stringify(e.param)
    };
    return this._initRequest(e.url, t, e);
  }
  initPut(e) {
    const t = e.url, s = {
      method: "put",
      headers: this._getHeader(e.ext),
      data: JSON.stringify(e.param)
    };
    return this._initRequest(t, s, e);
  }
  initDelete(e) {
    const t = e.url, s = {
      method: "delete",
      headers: this._getHeader(e.ext),
      data: JSON.stringify(e.param)
    };
    return this._initRequest(t, s, e);
  }
  initFile(e) {
    const t = {
      method: "post"
    }, s = this._getHeader(e.ext);
    t.headers = s;
    const o = new FormData();
    return Object.keys(e.param).forEach((r) => {
      const c = e.param[r];
      i.isArray(c) ? c.forEach((a) => {
        o.append(r, a);
      }) : o.append(r, e.param[r]);
    }), t.data = o, this._initRequest(e.url, t, e);
  }
  initFileDownLoad(e) {
    const t = this, s = {
      method: "post",
      responseType: "blob"
    }, o = i.isEmpty(e.options.method) ? "post" : e.options.method;
    s.method = o;
    const r = this._getHeader(e.ext);
    return r["Content-Type"] = "application/json;", s.headers = r, i.isEmpty(e.param) || (o === "get" ? s.params = e.param : s.data = JSON.stringify(e.param)), e.ext._operateType = "fileDownBinary", e.ext.uploadDownBinaryCallback = (c, a, b) => {
      const d = new FileReader();
      d.onload = function(m) {
        try {
          const p = JSON.parse(m.currentTarget.result), y = a.resultCallback ? a.resultCallback({ data: p }) : t._initResult({ data: p }, a.resultCode);
          y.success || b(y);
        } catch {
          const y = c.headers["content-disposition"];
          let f = "";
          i.isEmpty(y) ? f = e.param && e.param.fileName ? e.param.fileName : (/* @__PURE__ */ new Date()).getTime().toString() : f = window.decodeURIComponent(y.split("=")[1]), f = f.replace(/\"/g, "").replace(/'/g, "");
          let E = "";
          const x = f.lastIndexOf(".");
          x > -1 && (E = f.substring(x + 1));
          let _;
          switch (E) {
            case "xls":
            case "xlsx":
              _ = { type: "application/vnd.ms-excel" };
              break;
            case "csv":
              _ = { type: "text/csv" };
              break;
            case "doc":
            case "docx":
              _ = { type: "application/msword" };
              break;
            case "pdf":
              _ = { type: "application/pdf" };
              break;
          }
          const q = new Blob([c.data], _);
          if (window.navigator && window.navigator.msSaveOrOpenBlob)
            window.navigator.msSaveOrOpenBlob(q, f);
          else {
            const k = document.createElement("a");
            k.href = (window.URL || window.webkitURL).createObjectURL(q), k.download = f, k.style.display = "none", document.body.appendChild(k), k.click(), window.URL.revokeObjectURL(k.href);
          }
          b({ success: !0 });
        }
      }, d.readAsText(c.data);
    }, this._initRequest(e.url, s, e);
  }
  _getHeader(e) {
    const t = {
      "Content-Type": "application/json;charset=UTF-8",
      "X-Requested-With": "XMLHttpRequest"
    };
    if (e && e.headerCallback) {
      const s = e.headerCallback();
      if (!i.isEmpty(s))
        for (const [o, r] of Object.entries(s))
          t[o] = r;
    }
    return t;
  }
  _getExtInfo(e) {
    const t = i.getJsonClone(e);
    return t.isTimeOut = i.isBoolean(t.isTimeOut) ? t.isTimeOut : !0, t;
  }
  _timeOut(e, t) {
    const r = (/* @__PURE__ */ new Date()).getTime() - e.getTime() - 200, c = r > 0 ? 0 : Math.abs(r);
    c <= 0 ? t() : setTimeout(() => {
      t();
    }, c);
  }
  _initResult(e, t) {
    const s = { code: null, success: !1, msg: "", data: null };
    if (e.data) {
      s.code = e.data.code.toString();
      const o = t.success || "200";
      s.code === o ? (s.success = !0, s.data = e.data.data) : (s.success = !1, s.msg = e.data.message, s.data = e.data.data);
    }
    return s;
  }
  _initResultErr(e, t) {
    const s = { code: null, success: !1, msg: "Axios:Unknown error .", data: null }, o = i.isEmpty(t) ? `Axios:Unknown error ${e}` : t;
    return s.msg = o, s;
  }
  _setInterceptors() {
    w.interceptors.request.use((e) => (this.globalOptions.interceptorsRequestCallback && this.globalOptions.interceptorsRequestCallback(e), e && (!i.isEmpty(e.__retryCount) && e.__retryCount > 0 || (this._removeRequestPending(e), this._addRequestPending(e))), e), (e) => Promise.reject(e)), w.interceptors.response.use((e) => (this.globalOptions.interceptorsResponseCallback && this.globalOptions.interceptorsResponseCallback(e), this._removeRequestPending(e.config), e), (e) => {
      if (e.code === "ECONNABORTED" && e.message.indexOf("timeout") > -1) {
        const t = e.config;
        return !t || !t.retry || (t.__retryCount = t.__retryCount || 0, t.__retryCount >= t.retry) ? Promise.reject(e) : (t.__retryCount += 1, new Promise((o) => {
          setTimeout(function() {
            o();
          }, t.retryDelay || 1);
        }).then(function() {
          return w(t);
        }));
      } else
        return Promise.reject(e);
    });
  }
  _getRequestKeyMerge(e) {
    const t = e._requestKeyMerge, s = i.isBoolean(e.isRequestCancelRepeat) ? e.isRequestCancelRepeat : !0, o = [];
    return !i.isEmpty(e) && s && (i.isUndefined(t) ? (o.push(e.method), o.push(e.url), i.isEmpty(e._ran) || o.push(e._ran)) : ["method", "url", "params", "data", "_ran"].forEach((r) => {
      if (i.isExistValue(t, r) && !i.isEmpty(e[r])) {
        let c = e[r];
        r === "params" || r === "data" ? (i.isString(c) && (c = JSON.parse(c)), o.push(A.stringify(c))) : (r === "_ran" && i.isEmpty(c) && (c = (/* @__PURE__ */ new Date()).getTime()), o.push(c));
      }
    })), o.join("&");
  }
  _addRequestPending(e) {
    const t = this._getRequestKeyMerge(e);
    i.isEmpty(t) || (e.cancelToken = e.cancelToken || new w.CancelToken((s) => {
      this.requestPendingList.has(t) || this.requestPendingList.set(t, s);
    }));
  }
  _removeRequestPending(e) {
    const t = this._getRequestKeyMerge(e);
    !i.isEmpty(t) && this.requestPendingList.has(t) && (this.requestPendingList.get(t)(`AxiosCancelRepeatRequest: ${t}`), this.requestPendingList.delete(t));
  }
  cancelAll() {
    const e = [];
    for (const t of this.requestPendingList)
      e.push(t[0]);
    e.forEach((t) => {
      this.requestPendingList.get(t)(`AxiosCancelRepeatRequest: ${t}`), this.requestPendingList.delete(t);
    });
  }
  setResendAgain(e, t = {}) {
    const s = e.config, o = i.isUndefined(t.retryDelay) ? 500 : t.retryDelay;
    return !s || !s.retry ? Promise.reject(e) : new Promise((c) => {
      setTimeout(function() {
        c();
      }, o || 1);
    }).then(function() {
      return s.cancelToken = null, w(s);
    });
  }
  setGlobalOptions(e) {
    this.globalOptions = i.getJsonMerge(this.globalOptions, e || {});
  }
}
new I();
const G = ["name", "checked"], V = {
  key: 0,
  class: "switchery-txt"
}, W = ["innerHTML"], z = ["innerHTML"], X = {
  key: 0,
  class: "switchery-load-bg"
}, de = /* @__PURE__ */ U({
  name: "ClSwitchery",
  __name: "Index",
  props: {
    value: {
      type: Boolean,
      default: !1
    },
    name: String,
    className: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    color: {
      type: [String, Object],
      validator: (h) => typeof h == "object" ? h.checked || h.unChecked : typeof h == "string"
    },
    changeCallback: Function,
    isUseOnChangeCheck: {
      type: Boolean,
      default: !1
    },
    isShowLoad: {
      type: Boolean,
      default: !0
    },
    activeHtml: String,
    inactiveHtml: String
  },
  emits: ["update:value", "onChange"],
  setup(h, { expose: e, emit: t }) {
    const s = h, o = t, r = j("$ClGlobals"), c = H(null), a = N({
      isFirstComplete: !1,
      isOpen: s.value,
      buttonLeft: 0,
      isRunLoad: !1,
      colorChecked: "#2196f3",
      colorUnChecked: "#ffffff"
    }), b = O(() => {
      let n = s.name;
      return i.isEmpty(n) && (n = `switchery_${i.getRandom(8)}`), n;
    }), d = O(() => {
      const { colorChecked: n } = a;
      let l = "";
      const u = s.color;
      return i.isUndefined(u) ? l = n : i.isString(u) ? l = u : i.isObject(u) && (l = i.isExistJsonKey(u, "checked") ? u.checked : n), l;
    }), m = O(() => {
      const { colorUnChecked: n } = a;
      let l = "";
      const u = s.color;
      return i.isObject(u) && i.isExistJsonKey(u, "unChecked") ? l = u.unchecked : l = n, l;
    }), p = O(() => {
      const n = {
        "panel-switchery": !0,
        "switchery-transition-immediately": !a.isFirstComplete
      };
      return i.isEmpty(s.className) || s.className.split(" ").forEach((l) => {
        i.isEmpty(l) || (n[l] = !0);
      }), n;
    }), y = O(() => {
      const n = {
        "switchery-container": !0,
        "switchery-open": a.isOpen
      };
      return n["switchery-disabled"] = s.disabled, n;
    }), f = O(() => {
      const n = a.isOpen, l = n ? d.value : m.value, u = {
        "background-color": l
      };
      return u.transition = n ? "border 0.4s, box-shadow 0.4s, background-color 1.2s" : "border 0.4s, box-shadow 0.4s", u["box-shadow"] = n ? `${l} 0px 0px 0px 11px inset` : `${l} 0px 0px 0px 0px inset`, n && (u["border-color"] = l), u;
    }), E = O(() => {
      const n = {
        left: "0"
      };
      return a.isOpen && (n.left = `${a.buttonLeft}px`), n;
    }), x = (n) => {
      const l = P.getElementData(s);
      o("update:value", n), o("onChange", n, l);
    }, _ = () => {
      if (r && r.globalsOption && r.globalsOption.switchery) {
        const n = r.globalsOption.switchery;
        i.isExistJsonKey(n, "colorChecked") && (a.colorChecked = n.colorChecked), i.isExistJsonKey(n, "colorUnChecked") && (a.colorUnChecked = n.colorUnChecked);
      }
    }, q = () => {
      const n = c.value.clientWidth, l = c.value.querySelector(".switchery-button").clientWidth;
      a.buttonLeft = n === 0 ? 22 : n - l;
    }, k = () => {
      _(), q(), setTimeout(() => {
        a.isFirstComplete = !0;
      }, 250);
    };
    M(
      () => s.value,
      (n, l) => {
        n !== l && (a.isOpen = n);
      }
    ), F(() => {
      J(() => {
        k();
      });
    });
    const S = () => {
      if (!s.disabled) {
        q();
        const n = !a.isOpen;
        if (s.changeCallback && i.isFunction(s.changeCallback)) {
          a.isRunLoad = !0;
          const l = P.getElementData(s), u = s.changeCallback(n, l);
          if (u && u.then && i.isFunction(u.then))
            u.then((g) => {
              let T = !1;
              i.isBoolean(g) ? T = g : i.isObject(g) && i.isBoolean(g.success) && (T = g.success), T && (a.isOpen = n), a.isRunLoad = !1;
            });
          else {
            let g = !1;
            i.isBoolean(u) ? g = u : i.isObject(u) && i.isBoolean(u.success) && (g = u.success), g && (a.isOpen = n), a.isRunLoad = !1;
          }
        } else
          s.isUseOnChangeCheck ? a.isRunLoad = !0 : a.isOpen = n, x(n);
      }
    };
    return e({
      getValue: () => a.isOpen,
      setValue: (n, l = !1) => {
        a.isOpen = n, l && x(n);
      },
      setOnChangeResult: () => {
        s.isUseOnChangeCheck && i.isUndefined(s.changeCallback) && (a.isOpen = !a.isOpen, a.isRunLoad = !1);
      }
    }), (n, l) => (C(), R("label", {
      class: D(p.value)
    }, [
      L("input", {
        type: "checkbox",
        class: "switchery-input",
        name: b.value,
        checked: a.isOpen
      }, null, 8, G),
      L("span", {
        class: D(y.value),
        style: B(f.value),
        onClick: S,
        ref_key: "refElContainer",
        ref: c
      }, [
        h.activeHtml || h.inactiveHtml ? (C(), R("span", V, [
          a.isOpen ? (C(), R("span", {
            key: 0,
            innerHTML: h.activeHtml
          }, null, 8, W)) : (C(), R("span", {
            key: 1,
            innerHTML: h.inactiveHtml
          }, null, 8, z))
        ])) : (C(), R(v, { key: 1 }, [], 64)),
        L("span", {
          class: "switchery-button",
          style: B(E.value)
        }, [
          h.isShowLoad && a.isRunLoad ? (C(), K($, {
            key: 0,
            theme: "rotaryLine",
            size: "small"
          })) : (C(), R(v, { key: 1 }, [], 64))
        ], 4)
      ], 6),
      h.isShowLoad && a.isRunLoad ? (C(), R("div", X)) : (C(), R(v, { key: 1 }, [], 64))
    ], 2));
  }
});
export {
  de as default
};
//# sourceMappingURL=ClSwitchery.js.map
