import { defineComponent as g, computed as p, openBlock as b, createBlock as v } from "vue";
import { aZ as k, bf as C } from "./main-CI6Q9nmO.js";
const F = /* @__PURE__ */ g({
  __name: "AutocompleteFilter",
  props: {
    header: {
      type: Object,
      required: !0
    },
    filters: {
      type: Array,
      default: () => []
    },
    filterValue: {
      type: [String, Number, Object, Array, void 0, null],
      default: null
    },
    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
    }
  },
  emits: ["update:filters"],
  setup(t, { emit: y }) {
    const e = t, u = y;
    function f() {
      return String(e.header.key || e.header.value || (e.header.title ? `filter_${e.header.title}` : `filter_${Date.now()}`));
    }
    const m = p(() => !e.header.filterOptions || !Array.isArray(e.header.filterOptions) ? [] : e.header.filterOptions), c = p({
      get: () => e.filterValue === null || e.filterValue === void 0 ? e.header.multiple ? [] : null : e.filterValue,
      set: (l) => {
        const i = f();
        if (!i) return;
        if (e.header.multiple) {
          if (!l || Array.isArray(l) && l.length === 0) {
            const o = e.filters.filter((s) => s.key !== i);
            u("update:filters", o);
            return;
          }
          const r = e.filters.findIndex((o) => o.key === i), a = [...e.filters];
          r >= 0 ? a[r].value = l : a.push({
            key: i,
            value: l,
            type: "autocomplete"
          }), u("update:filters", a);
          return;
        }
        if (l == null) {
          const r = e.filters.filter((a) => a.key !== i);
          u("update:filters", r);
          return;
        }
        const n = e.filters.findIndex((r) => r.key === i), d = [...e.filters];
        n >= 0 ? d[n].value = l : d.push({
          key: i,
          value: l,
          type: "autocomplete"
        }), u("update:filters", d);
      }
    });
    function h() {
      const l = f(), i = e.filters.filter((n) => n.key !== l);
      u("update:filters", i);
    }
    return (l, i) => {
      var n, d, r, a, o;
      return b(), v(k, {
        modelValue: c.value,
        "onUpdate:modelValue": i[0] || (i[0] = (s) => c.value = s),
        label: e.header.title || "",
        items: m.value,
        clearable: t.clearable,
        density: ((n = t.inputConfig) == null ? void 0 : n.density) ?? t.density,
        "hide-details": ((d = t.inputConfig) == null ? void 0 : d.hideDetails) ?? t.hideDetails,
        "variant-style": ((r = t.inputConfig) == null ? void 0 : r.variant) ?? t.variant,
        "bg-color": ((a = t.inputConfig) == null ? void 0 : a.backgroundColor) ?? t.backgroundColor,
        "disable-error-handling": ((o = t.inputConfig) == null ? void 0 : o.disableErrorHandling) ?? t.disableErrorHandling,
        multiple: e.header.multiple,
        chips: e.header.chips,
        filter: !0,
        class: "filter-input",
        "aria-label": e.header.title || "Filtre",
        "onClick:clear": h
      }, null, 8, ["modelValue", "label", "items", "clearable", "density", "hide-details", "variant-style", "bg-color", "disable-error-handling", "multiple", "chips", "aria-label"]);
    };
  }
}), I = /* @__PURE__ */ C(F, [["__scopeId", "data-v-d44a48a9"]]);
export {
  I as default
};
