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