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