import { defineComponent as V, computed as w, ref as h, watch as u, resolveComponent as i, openBlock as F, createBlock as g, withCtx as d, createVNode as A, createElementVNode as k, normalizeClass as K } from "vue";
import { c as s } from "./number-BVg7EKPV.js";
const _ = ["value", "disabled"], C = /* @__PURE__ */ V({
  __name: "NumberPrecisionInput",
  props: {
    modelValue: {},
    label: {},
    helperText: {},
    step: {},
    rules: {},
    disabled: { type: Boolean }
  },
  emits: ["update:modelValue"],
  setup(m, { emit: p }) {
    const r = m, n = p, c = w(() => s(r.step ?? 1).precision), l = h(r.modelValue.toString());
    u(
      () => r.modelValue,
      (e) => {
        l.value = e.toString();
      },
      { immediate: !0 }
    ), u([() => l.value], ([e]) => {
      e === "-" || e === "." ? n("update:modelValue", 0) : n("update:modelValue", +e);
    });
    const f = (e) => {
      if (e.ctrlKey || e.altKey || e.metaKey || ["Backspace", "Tab", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(
        e.key
      ))
        return;
      const t = e.currentTarget, o = +`${t.value}${e.key}`;
      if (isFinite(o)) {
        s(o).precision > c.value && e.preventDefault();
        return;
      }
      t.value.length === 0 && (e.key === "-" || e.key === ".") || e.preventDefault();
    };
    return (e, t) => {
      const o = i("FmField"), a = i("FmFormGroup");
      return F(), g(a, {
        disabled: e.disabled,
        modelValue: e.modelValue,
        rules: e.rules,
        "helper-text": e.helperText,
        label: e.label
      }, {
        default: d(({ invalid: b }) => [
          A(o, { invalid: b }, {
            default: d(() => [
              k("input", {
                value: l.value,
                onInput: t[0] || (t[0] = (y) => l.value = y.target.value),
                onKeydown: f,
                inputmode: "numeric",
                class: K({
                  "fm-text-field--input fm-typo-en-body-lg-400": !0,
                  "text-fm-color-typo-primary": !e.disabled,
                  "text-fm-color-typo-disabled": e.disabled
                }),
                disabled: e.disabled
              }, null, 42, _)
            ]),
            _: 2
          }, 1032, ["invalid"])
        ]),
        _: 1
      }, 8, ["disabled", "modelValue", "rules", "helper-text", "label"]);
    };
  }
});
export {
  C as _
};
