import { defineComponent, useModel, watch, resolveComponent, openBlock, createBlock, createSlots, withCtx, renderSlot, mergeModels } from 'vue';

var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "FmInputNumber" },
  __name: "index",
  props: /* @__PURE__ */ mergeModels({
    placeholder: {
      type: String,
      default: "\u8BF7\u8F93\u5165\u91D1\u989D"
    },
    defaultValue: {
      type: Number,
      default: -1
    },
    bType: {
      type: String,
      default: "money"
    }
  }, {
    "modelValue": { required: true, default: 0 },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const modelValue = useModel(__props, "modelValue");
    const props = __props;
    const handleInput = (val) => {
      if (val === "" || val === null || val === void 0) {
        modelValue.value = props.defaultValue !== -1 ? props.defaultValue : 0;
        return;
      }
      if (props.bType == "number") {
        const num = parseInt(val, 10);
        modelValue.value = Number.isNaN(num) ? props.defaultValue : num;
        return;
      }
      let cleaned = String(val).replace(/[^\d.]/g, "");
      const dotIndex = cleaned.indexOf(".");
      if (dotIndex !== -1) {
        const before = cleaned.substring(0, dotIndex + 1);
        const after = cleaned.substring(dotIndex + 1).replace(/\./g, "");
        cleaned = before + after;
      }
      if (cleaned.startsWith(".")) {
        cleaned = "0" + cleaned;
      }
      const parts = cleaned.split(".");
      parts[0] = parts[0].replace(/^0+/, "") || "0";
      cleaned = parts.join(".");
      if (cleaned.includes(".")) {
        const [intPart, decPart] = cleaned.split(".");
        cleaned = `${intPart}.${decPart.substring(0, 2)}`;
      }
      modelValue.value = cleaned;
    };
    watch(() => modelValue.value, (newvalue, oldValue) => {
      if (newvalue == "") {
        modelValue.value = props.defaultValue == -1 ? 0 : props.defaultValue;
      }
    });
    return (_ctx, _cache) => {
      const _component_el_input = resolveComponent("el-input");
      return openBlock(), createBlock(_component_el_input, {
        modelValue: modelValue.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
        placeholder: __props.placeholder,
        onInput: handleInput
      }, createSlots({
        _: 2
        /* DYNAMIC */
      }, [
        _ctx.$slots.prepend ? {
          name: "prepend",
          fn: withCtx(() => [
            renderSlot(_ctx.$slots, "prepend")
          ]),
          key: "0"
        } : void 0,
        _ctx.$slots.append ? {
          name: "append",
          fn: withCtx(() => [
            renderSlot(_ctx.$slots, "append")
          ]),
          key: "1"
        } : void 0,
        _ctx.$slots.prefix ? {
          name: "prefix",
          fn: withCtx(() => [
            renderSlot(_ctx.$slots, "prefix")
          ]),
          key: "2"
        } : void 0,
        _ctx.$slots.suffix ? {
          name: "suffix",
          fn: withCtx(() => [
            renderSlot(_ctx.$slots, "suffix")
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["modelValue", "placeholder"]);
    };
  }
});

export { _sfc_main as default };
