import { defineComponent as H, ref as R, computed as D, onMounted as j, nextTick as q, openBlock as G, createElementBlock as J, normalizeClass as x, renderSlot as Q, reactive as K, watch as se, useSlots as ie, resolveComponent as Z, createVNode as _, createSlots as ue, withCtx as F, createElementVNode as z } from "vue";
import { C as s } from "./base-PQGakkrl.js";
import { _ as ce } from "./Index.vue_vue_type_script_setup_true_lang-DWw1B8Z2.js";
import { D as re } from "./drag-CzfhSB0g.js";
import "js-cookie";
import "decimal.js";
const de = /* @__PURE__ */ H({
  name: "ClInputnumberButton",
  __name: "Button",
  props: {
    className: {},
    isDisabled: { type: Boolean },
    checkDownBeforeCallback: { type: Function }
  },
  emits: ["onLongDownStart", "onLongDownEnd"],
  setup(l, { emit: E }) {
    const n = l, C = E, f = R(null), c = {
      longDownInterval: null,
      isMoveBoundary: !1
    }, d = D(() => {
      const a = {
        "inputNumber-controls": !0
      }, r = n.className;
      return r && !s.isEmpty(r) && r.split(" ").forEach((i) => {
        s.isEmpty(i) || (a[i] = !0);
      }), a["inputNumber-controls-disabled"] = n.isDisabled || !1, a;
    }), b = () => {
      C("onLongDownStart");
    }, v = () => {
      C("onLongDownEnd");
    }, T = () => {
      let a = !0;
      return n.checkDownBeforeCallback && (a = n.checkDownBeforeCallback()), a;
    }, y = () => {
      c.longDownInterval && (clearInterval(c.longDownInterval), c.longDownInterval = null);
    }, w = () => {
      b(), y(), c.longDownInterval = setInterval(() => {
        n.isDisabled ? B() : b();
      }, 200);
    }, L = (a) => {
      f.value === a.target || f.value?.contains(a.target) ? c.isMoveBoundary && (c.isMoveBoundary = !1, w()) : (y(), c.isMoveBoundary = !0);
    }, B = () => {
      y(), v();
    }, O = () => {
      const a = {
        start(r) {
          let i = !1;
          return r.buttons === 1 && (i = T(), i && (n.isDisabled || w())), i;
        },
        ing: (r) => {
          L(r);
        },
        end: () => {
          B();
        }
      };
      f.value && new re(f.value, a);
    };
    return j(() => {
      q(() => {
        O();
      });
    }), (a, r) => (G(), J("span", {
      ref_key: "refElButton",
      ref: f,
      class: x(d.value)
    }, [
      Q(a.$slots, "icon")
    ], 2));
  }
}), ve = /* @__PURE__ */ H({
  name: "ClInputNumber",
  components: {
    ClInput: ce,
    ClInputnumberButton: de
  },
  __name: "Index",
  props: {
    size: {
      type: String,
      default: "large",
      validator: (l) => ["", "large", "small"].indexOf(l) !== -1
    },
    btnShowType: {
      type: String,
      default: "fixed",
      validator: (l) => ["fixed", "focus"].indexOf(l) !== -1
    },
    btnTheme: {
      type: String,
      default: "leftRight",
      validator: (l) => ["leftRight", "upDown"].indexOf(l) !== -1
    },
    value: {
      type: [String, Number],
      default: ""
    },
    placeholder: {
      type: String,
      default: ""
    },
    className: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    isClean: {
      type: Boolean,
      default: !0
    },
    isTextRead: {
      type: Boolean,
      default: !1
    },
    min: {
      type: Number,
      default: void 0
    },
    max: {
      type: Number,
      default: void 0
    },
    isLoop: {
      type: Boolean,
      default: !1
    },
    decimal: {
      type: Number,
      default: 0
    },
    fillZeroCount: {
      type: Number,
      default: 0
    },
    btnStep: {
      type: Number,
      default: 1
    },
    btnClsIconSub: {
      type: String,
      default: ""
    },
    btnClsIconAdd: {
      type: String,
      default: ""
    },
    operateBtnDownBeforeCallback: Function,
    calculationOperateValueCallback: Function
  },
  emits: ["update:value", "onChange"],
  setup(l, { emit: E }) {
    const n = l, C = E, f = R(null), c = K({
      isHover: !1,
      isFocus: !1
    }), d = R(""), b = K({
      subtractDisabled: !1,
      addDisabled: !1
    }), v = {
      upDown: {
        subtract: "clIconFont clIcon-angle-up",
        add: "clIconFont clIcon-angle-down"
      },
      leftRight: {
        subtract: "clIconFont clIcon-minus",
        add: "clIconFont clIcon-plus"
      },
      btnShowFixed: n.btnShowType === "fixed",
      btnShowFocus: n.btnShowType === "focus"
    }, T = D(() => !s.isUndefined(oe.textPrepend)), y = D(() => {
      const t = n.decimal || 0, e = (n.btnStep || 1).toString();
      let o = t;
      if (e.indexOf(".") > -1) {
        const u = e.split(".")[1].length;
        t < u && (o = u);
      }
      return o;
    }), w = D(() => (n.fillZeroCount || 0) > 0), L = D(() => {
      const t = {
        "panel-inputNumber": !0,
        "inputNumber-disabled": n.disabled || !1
      }, { className: e, size: o } = n;
      return e && !s.isEmpty(e) && e.split(" ").forEach((u) => {
        s.isEmpty(u) || (t[u] = !0);
      }), t[`inputNumber-btn-${n.btnTheme || "leftRight"}`] = !0, t[`inputNumber-btn-${n.btnShowType || "fixed"}`] = !0, t["inputNumber-hover"] = c.isHover, t["inputNumber-focus"] = c.isFocus, t[`inputNumber-${o || "large"}`] = !0, t;
    }), B = D(() => {
      const t = {};
      let e = "";
      if (n.btnClsIconSub && !s.isEmpty(n.btnClsIconSub))
        e = n.btnClsIconSub;
      else {
        const o = n.btnTheme || "leftRight";
        v[o] && (e = v[o].subtract);
      }
      return e.length > 0 && (t[e] = !0), t;
    }), O = D(() => {
      const t = {};
      let e = "";
      if (n.btnClsIconAdd && !s.isEmpty(n.btnClsIconAdd))
        e = n.btnClsIconAdd;
      else {
        const o = n.btnTheme || "leftRight";
        v[o] && (e = v[o].add);
      }
      return e.length > 0 && (t[e] = !0), t;
    }), a = () => {
      const t = d.value;
      C("update:value", t), C("onChange", t);
    }, r = (t) => {
      t === d.value && f.value?.setValue(t), d.value = t;
    }, i = (t, e) => {
      let o, u = !1, g = !1;
      if (n.calculationOperateValueCallback) {
        const I = n.calculationOperateValueCallback({ value: t, type: e });
        o = I.value, u = I.subtractDisabled, g = I.addDisabled;
      } else {
        const I = s.isEmpty(t) ? 0 : Number(t), h = n.min, S = n.max, { isLoop: N = !1 } = n, M = s.isUndefined(h), A = s.isUndefined(S), le = n.btnStep || 1;
        let m = I;
        if (e && !s.isEmpty(e)) {
          m += le * (e === "subtract" ? -1 : 1);
          const P = m.toString();
          if (P.indexOf(".") > -1) {
            const ae = P.split(".")[1].length, U = y.value;
            U.toString().length < ae && (m = Number(m.toFixed(U)));
          }
        }
        !M && m <= h ? (N || (u = !0), o = m < h && N && !A ? S : h) : !A && m >= S ? (N || (g = !0), o = m > S && N && !M ? h : S) : o = m;
      }
      w.value && (o = s.getFillZero(o)), r(o.toString()), b.subtractDisabled = u, b.addDisabled = g;
    }, p = (t) => {
      c.isFocus = t, t && f.value?.focus();
    }, W = () => {
      i(n.value);
    };
    j(() => {
      q(() => {
        W();
      });
    }), se(
      () => n.value,
      (t, e) => {
        t !== e && t !== d.value && i(t);
      }
    );
    let k;
    const X = (t) => {
      n.disabled || (k && (clearTimeout(k), k = null), k = setTimeout(() => {
        s.isEmpty(t) ? (r(""), b.subtractDisabled = !1, b.addDisabled = !1) : i(t), a();
      }, 100));
    }, Y = (t) => {
      if (!n.disabled && !n.isTextRead) {
        let e = t.keyCode;
        s.isUndefined(e) || (e = e.toString(), e === "37" || e === "40" ? (i(d.value, "subtract"), p(!0)) : (e === "38" || e === "39") && (i(d.value, "add"), p(!0)));
      }
    }, ee = (t) => {
      if (!n.disabled && !n.isTextRead) {
        let e = t.keyCode;
        s.isUndefined(e) || (e = e.toString(), (e === "37" || e === "40" || e === "38" || e === "39") && (p(!0), a()));
      }
    }, te = () => {
      p(!0);
    }, ne = () => {
      p(!1);
    }, $ = (t) => {
      i(d.value, t), p(!0);
    }, V = () => {
      a(), p(!0);
    }, oe = ie();
    return (t, e) => {
      const o = Z("cl-input"), u = Z("cl-inputnumber-button");
      return G(), J("div", {
        class: x(L.value)
      }, [
        _(o, {
          ref_key: "refElInput",
          ref: f,
          value: d.value,
          placeholder: l.placeholder,
          disabled: l.disabled,
          isReadonly: l.isTextRead,
          isClean: l.isClean,
          isNumber: !w.value,
          decimal: y.value,
          theme: "icon",
          onOnChange: X,
          onOnKeydown: Y,
          onOnKeyup: ee,
          onOnFocus: te,
          onOnBlur: ne
        }, ue({ _: 2 }, [
          T.value ? {
            name: "prepend",
            fn: F(() => [
              Q(t.$slots, "textPrepend")
            ]),
            key: "0"
          } : void 0
        ]), 1032, ["value", "placeholder", "disabled", "isReadonly", "isClean", "isNumber", "decimal"]),
        _(u, {
          className: "inputNumber-subtract",
          isDisabled: l.disabled || b.subtractDisabled,
          checkDownBeforeCallback: l.operateBtnDownBeforeCallback,
          onOnLongDownStart: e[0] || (e[0] = (g) => $("subtract")),
          onOnLongDownEnd: e[1] || (e[1] = (g) => V())
        }, {
          icon: F(() => [
            z("i", {
              class: x(B.value)
            }, null, 2)
          ]),
          _: 1
        }, 8, ["isDisabled", "checkDownBeforeCallback"]),
        _(u, {
          className: "inputNumber-add",
          isDisabled: l.disabled || b.addDisabled,
          checkDownBeforeCallback: l.operateBtnDownBeforeCallback,
          onOnLongDownStart: e[2] || (e[2] = (g) => $("add")),
          onOnLongDownEnd: e[3] || (e[3] = (g) => V())
        }, {
          icon: F(() => [
            z("i", {
              class: x(O.value)
            }, null, 2)
          ]),
          _: 1
        }, 8, ["isDisabled", "checkDownBeforeCallback"])
      ], 2);
    };
  }
});
export {
  ve as _
};
//# sourceMappingURL=Index.vue_vue_type_script_setup_true_lang-BxtgFrvB.js.map
