import { defineComponent as k, ref as h, watch as x, computed as T, openBlock as V, createElementBlock as F, createVNode as w } from "vue";
import { b9 as S, bf as D } from "./main-CI6Q9nmO.js";
const E = { class: "number-filter-container" }, B = /* @__PURE__ */ k({
  __name: "NumberFilter",
  props: {
    header: {
      type: Object,
      required: !0
    },
    filters: {
      type: Array,
      default: () => []
    },
    filterValue: {
      type: [Number, String],
      default: ""
    },
    inputConfig: {
      type: Object,
      default: () => ({})
    },
    disableErrorHandling: {
      type: Boolean,
      default: !1
    },
    variant: {
      type: String,
      default: "outlined"
    },
    hideDetails: {
      type: Boolean,
      default: !0
    },
    density: {
      type: String,
      default: "compact"
    },
    backgroundColor: {
      type: String,
      default: "white"
    },
    clearable: {
      type: Boolean,
      default: !0
    },
    debounceTime: {
      type: Number,
      default: 300
    }
  },
  emits: ["update:filters"],
  setup(l, { emit: y }) {
    const e = l, s = y, d = h(e.filterValue || ""), u = h(null);
    x(() => e.filters, (t) => {
      t.length === 0 && (u.value !== null && (clearTimeout(u.value), u.value = null), d.value = "");
    });
    function c() {
      return !e.header || !e.header.key && !e.header.value && !e.header.title ? `filter_${Date.now()}` : String(e.header.key || e.header.value || (e.header.title ? `filter_${e.header.title}` : `filter_${Date.now()}`));
    }
    function p(t) {
      const a = /^([=<>]{1,2})?(.*)$/.exec(t);
      if (!a) return "";
      const i = a[1] || "";
      let r = a[2] || "";
      return r = r.replace(/[^0-9.,]/g, ""), i + r;
    }
    const f = T({
      get: () => d.value,
      set: (t) => {
        var o;
        const n = t != null ? String(t) : "", a = p(n);
        d.value = a, u.value !== null && clearTimeout(u.value);
        const i = ((o = e.inputConfig) == null ? void 0 : o.debounceTime) ?? e.debounceTime;
        i === 0 || void 0 ? g(a) : u.value = window.setTimeout(() => {
          g(a);
        }, i);
      }
    });
    function g(t) {
      const n = c();
      if (!e.header || Object.keys(e.header).length, t === "" || t === "0") {
        s("update:filters", e.filters.filter((o) => o.key !== n));
        return;
      }
      const a = e.filters.findIndex((o) => o.key === n), i = [...e.filters], r = /^[=<>]{1,2}/.test(t);
      a >= 0 ? i[a].value = r ? t : parseFloat(t.replace(",", ".")) : i.push({
        key: n,
        value: r ? t : parseFloat(t.replace(",", ".")),
        type: "number"
      }), s("update:filters", i);
    }
    function v() {
      d.value = "";
      const t = c();
      s("update:filters", e.filters.filter((n) => n.key !== t));
    }
    return (t, n) => {
      var a, i, r, o, m, b;
      return V(), F("div", E, [
        w(S, {
          modelValue: f.value,
          "onUpdate:modelValue": n[0] || (n[0] = (C) => f.value = C),
          label: l.header.title || "",
          type: "text",
          clearable: ((a = l.inputConfig) == null ? void 0 : a.clearable) ?? l.clearable,
          density: ((i = l.inputConfig) == null ? void 0 : i.density) ?? l.density,
          "hide-details": ((r = l.inputConfig) == null ? void 0 : r.hideDetails) ?? l.hideDetails,
          "hide-messages": l.header.hideMessages,
          "disable-error-handling": ((o = l.inputConfig) == null ? void 0 : o.disableErrorHandling) ?? l.disableErrorHandling,
          variant: ((m = l.inputConfig) == null ? void 0 : m.variant) ?? l.variant,
          "bg-color": ((b = l.inputConfig) == null ? void 0 : b.backgroundColor) ?? l.backgroundColor,
          class: "filter-input",
          "onClick:clear": v
        }, null, 8, ["modelValue", "label", "clearable", "density", "hide-details", "hide-messages", "disable-error-handling", "variant", "bg-color"])
      ]);
    };
  }
}), O = /* @__PURE__ */ D(B, [["__scopeId", "data-v-f3c6e802"]]);
export {
  O as default
};
