import '@das-fed/ui/packages/components/input-number/style.css';
import { defineComponent as oe, mergeModels as F, useCssVars as re, computed as c, ref as u, useModel as ne, watch as M, onMounted as le, onBeforeUnmount as ue, createElementBlock as _, openBlock as I, normalizeClass as ae, createCommentVNode as g, createVNode as H, unref as k, withCtx as se, mergeProps as ie, Fragment as ve, createBlock as de, createElementVNode as ce, normalizeStyle as fe, toDisplayString as pe, nextTick as K } from "vue";
import { withInstall as me } from "@das-fed/utils/with-install/index";
import { getVarValue as be, setThemeRule as he } from "@das-fed/web/packages/theme/index";
import { ElInputNumber as Le } from "element-plus";
import "element-plus/es/components/input-number/style/css";
import { DasTooltip as ye } from "@das-fed/ui/packages/components/tooltip/index";
import { DasErrorOverlayModel as Ee } from "@das-fed/ui/packages/components/error-overlay-model/index";
import { calcTextWidth as Be } from "@das-fed/utils/common-tools";
const Me = {
  key: 0,
  class: "das-input-number-error-label-content"
}, Ie = {
  inheritAttrs: !1
}, ge = /* @__PURE__ */ oe({
  ...Ie,
  __name: "App",
  props: /* @__PURE__ */ F({
    modelValue: { default: 0 },
    placeholder: {},
    size: { default: "default" },
    controlsPosition: { default: "" },
    baseLine: { type: Boolean },
    disabled: { type: Boolean, default: !1 },
    width: {},
    isView: { type: Boolean, default: !1 },
    errorMode: { default: "default" },
    error: { type: Boolean, default: !1 },
    errorLabel: { default: "" },
    errorModelZIndex: { default: 2e3 },
    noSetDefaultVal: { type: Boolean },
    disabledTooltip: { type: Boolean }
  }, {
    modelValue: { type: Number, default: 0 },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ F(["update:modelValue", "input", "change"], ["update:modelValue"]),
  setup(f, { expose: V, emit: L }) {
    re((e) => ({
      "1b8e8582": O.value,
      "3c7330eb": U.value
    }));
    const o = f, p = L, r = u(null), a = u(null), w = u(null), y = c(() => o.isView || o.disabled), n = ne(f, "modelValue"), E = c(() => y.value ? o.noSetDefaultVal ? "" : "-" : o.placeholder ?? ""), O = c(() => o.width ? o.width : o.controlsPosition ? o.baseLine ? "230px" : "80px" : "100px"), U = c(() => {
      if (o.size === "default")
        return o.controlsPosition === "right" && o.baseLine ? "25px" : "28px";
      if (o.size === "table") return "30px";
    }), s = u(!1), j = c(
      () => !n.value && typeof n.value != "number" ? E.value : n.value
    ), B = c(() => {
      var e;
      return a.value ? (e = a.value.$el) == null ? void 0 : e.querySelector(".el-input__inner") : null;
    }), $ = () => {
      const e = o.size === "table" ? 12 : 14;
      return Be(E.value, e);
    }, i = u(0), v = u(0);
    M(
      () => B.value,
      (e) => {
        setTimeout(() => {
          const t = e;
          t && (i.value = (t == null ? void 0 : t.offsetWidth) ?? 0, v.value = !n.value && typeof n.value != "number" ? $() : t == null ? void 0 : t.scrollWidth);
        }, 200);
      }
    );
    const N = () => {
      K(() => {
        var e, t;
        B.value && (i.value = ((e = B.value) == null ? void 0 : e.offsetWidth) ?? 0, v.value = !n.value && typeof n.value != "number" ? $() : (t = B.value) == null ? void 0 : t.scrollWidth, (i.value === v.value || v.value - i.value < 1) && (s.value = !1));
      });
    };
    M(() => [n.value, E.value], N), M(
      () => {
        var e;
        return (e = w.value) == null ? void 0 : e.$tooltipRef.popperRef.contentRef;
      },
      (e) => {
        e && (e.addEventListener("mouseenter", function() {
          s.value = !0, d.value && clearTimeout(d.value);
        }), e.addEventListener("mouseleave", function() {
          d.value = setTimeout(() => {
            s.value = !1;
          }, 200);
        }));
      }
    );
    const G = (e) => {
      const t = e.code;
      return ["KeyE", "Equal", "Minus"].includes(t) ? (e.returnValue = !1, !1) : !0;
    }, J = (e) => {
      !e && e !== 0 && (n.value = e), p("input", e);
    }, Q = (e, t) => {
      p("change", e, t);
    }, S = u(n.value), X = () => {
      S.value !== n.value && (p("change", n.value, S.value), S.value = n.value);
    }, P = () => {
      o.error || r.value.classList.add("input-inner-hover");
    }, D = () => {
      r.value.classList.contains("input-inner-hover") && r.value.classList.remove("input-inner-hover");
    }, z = () => {
      o.error || r.value.classList.add("decrease-btn-hover");
    }, q = () => {
      r.value.classList.contains("decrease-btn-hover") && r.value.classList.remove("decrease-btn-hover");
    }, W = () => {
      o.error || r.value.classList.add("increase-btn-hover");
    }, C = () => {
      r.value.classList.contains("increase-btn-hover") && r.value.classList.remove("increase-btn-hover");
    }, T = u(!1), Y = u({
      display: "block",
      color: be("--das-ui-input-error-color").value,
      "white-space": "break-spaces"
    }), d = u(), R = () => {
      N(), i.value === v.value || v.value - i.value < 1 ? s.value = !1 : (s.value = !0, d.value && clearTimeout(d.value)), o.errorMode === "overlay" && (T.value = !0);
    }, A = () => {
      d.value = setTimeout(() => {
        o.errorMode === "overlay" ? T.value = !1 : s.value = !1;
      }, 200);
    }, ee = () => {
      var e, t;
      (e = a.value) == null || e.$el.addEventListener("mouseenter", R), (t = a.value) == null || t.$el.addEventListener("mouseleave", A);
    }, te = () => {
      var e, t;
      (e = a.value) == null || e.$el.removeEventListener("mouseenter", R), (t = a.value) == null || t.$el.removeEventListener("mouseleave", A);
    }, Z = () => {
      y.value || K(() => {
        var m, b, h;
        const e = (m = r.value) == null ? void 0 : m.querySelector(".el-input__inner");
        e && (e.addEventListener("mouseenter", P), e.addEventListener("mouseleave", D));
        const t = (b = r.value) == null ? void 0 : b.querySelector(".el-input-number__decrease");
        t && (t.addEventListener("mouseenter", z), t.addEventListener("mouseleave", q));
        const l = (h = r.value) == null ? void 0 : h.querySelector(".el-input-number__increase");
        l && (l.addEventListener("mouseenter", W), l.addEventListener("mouseleave", C));
      });
    }, x = () => {
      var m, b, h;
      const e = (m = r.value) == null ? void 0 : m.querySelector(".el-input__inner");
      e && (e.removeEventListener("mouseenter", P), e.removeEventListener("mouseleave", D));
      const t = (b = r.value) == null ? void 0 : b.querySelector(".el-input-number__decrease");
      t && (t.removeEventListener("mouseenter", z), t.removeEventListener("mouseleave", q));
      const l = (h = r.value) == null ? void 0 : h.querySelector(".el-input-number__increase");
      l && (l.removeEventListener("mouseenter", W), l.removeEventListener("mouseleave", C));
    };
    return M(
      () => y.value,
      (e) => {
        if (e) {
          if (o.controlsPosition === "right") return;
          x();
        } else {
          if (o.controlsPosition === "right") return;
          Z();
        }
      }
    ), le(() => {
      ee(), o.controlsPosition !== "right" && Z();
    }), ue(() => {
      te(), o.controlsPosition !== "right" && x();
    }), V({
      $elInputNumber: a
    }), (e, t) => (I(), _(
      "div",
      {
        ref_key: "$inputNumber",
        ref: r,
        class: ae([
          "das-ui-input-number",
          e.controlsPosition === "" ? "default" : e.baseLine ? "base-line" : "controls-right",
          e.isView ? "is-view" : "",
          e.disabled ? "is-disabled" : "",
          e.noSetDefaultVal ? "nodefault" : "",
          `size-${e.size}`
        ])
      },
      [
        g(" 这里tooltip不能使用v-model:visible 有响应问题 "),
        H(k(ye), {
          ref_key: "inputTooltipRef",
          ref: w,
          effect: "light",
          placement: "top",
          manual: !0,
          visible: s.value,
          disabled: e.disabledTooltip,
          content: j.value
        }, {
          default: se(() => [
            H(k(Le), ie({
              ref_key: "$elInputNumber",
              ref: a,
              class: { "das-input-number-error": e.error },
              modelValue: n.value,
              "onUpdate:modelValue": t[0] || (t[0] = (l) => n.value = l),
              readonly: y.value,
              "controls-position": e.controlsPosition,
              placeholder: E.value
            }, e.$attrs, {
              onKeydown: G,
              onInput: J,
              onBlur: X,
              onChange: Q
            }), null, 16, ["class", "modelValue", "readonly", "controls-position", "placeholder"])
          ]),
          _: 1
          /* STABLE */
        }, 8, ["visible", "disabled", "content"]),
        e.error && e.errorLabel ? (I(), _(
          ve,
          { key: 0 },
          [
            e.errorMode === "default" ? (I(), _("div", Me, [
              ce(
                "span",
                {
                  style: fe(Y.value)
                },
                pe(e.errorLabel),
                5
                /* TEXT, STYLE */
              )
            ])) : g("v-if", !0),
            e.errorMode === "overlay" && T.value ? (I(), de(k(Ee), {
              key: 1,
              errorLabel: e.errorLabel,
              getEl: () => {
                var l;
                return (l = a.value) == null ? void 0 : l.$el;
              },
              errorModelZIndex: e.errorModelZIndex
            }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : g("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : g("v-if", !0)
      ],
      2
      /* CLASS */
    ));
  }
}), Ve = (f, V) => {
  const L = f.__vccOpts || f;
  for (const [o, p] of V)
    L[o] = p;
  return L;
}, Se = /* @__PURE__ */ Ve(ge, [["__scopeId", "data-v-97241aec"]]), Te = {
  "--das-ui-input-number-border-view-color": "#E5E5E5",
  "--das-ui-input-number-color": "#212121",
  "--das-ui-input-number-border-color": "#D9D9D9",
  "--das-ui-input-number-button-color": "#666666",
  "--das-ui-input-number-button-bg-color": "#ffffff",
  "--das-ui-input-number-active-color": "#5582F3",
  "--das-ui-input-number-disabled-color": "#B2B2B2",
  "--das-ui-input-number-overlay-error-color": "#FB2323",
  "--das-ui-input-number-default-placeholder-color": "#B2B2B2"
};
he(Te);
const qe = me(Se), We = () => u(null), Ce = { name: "input-number 步进器" };
export {
  qe as DasInputNumber,
  We as DasInputNumberRef,
  Ce as default
};
