import { defineComponent as C, computed as c, ref as F, openBlock as S, createElementBlock as A, createVNode as O } from "vue";
import { b4 as B, bf as E } from "./main-CI6Q9nmO.js";
const D = {
  emptyValue: "(vide)"
}, p = {}, I = { class: "select-filter-wrapper" }, N = /* @__PURE__ */ C({
  __name: "SelectFilter",
  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(r, { emit: g }) {
    const e = r, d = g;
    function y() {
      return String(e.header.key || e.header.value || (e.header.title ? `filter_${e.header.title}` : `filter_${Date.now()}`));
    }
    const m = c(() => {
      if (!e.header.filterOptions || !Array.isArray(e.header.filterOptions))
        return [];
      const l = [];
      return e.header.filterOptions.forEach((t) => {
        t.text === void 0 || t.text === null || t.text === "" ? l.push({ text: D.emptyValue, value: t.value }) : l.push(t);
      }), l;
    }), o = c({
      get: () => e.filterValue === null || e.filterValue === void 0 ? e.header.multiple ? [] : null : e.filterValue,
      set: (l) => {
        const t = y();
        if (!t) return;
        if (e.header.multiple) {
          if (!l || Array.isArray(l) && l.length === 0) {
            const u = e.filters.filter((f) => f.key !== t);
            d("update:filters", u);
            return;
          }
          const i = e.filters.findIndex((u) => u.key === t), a = [...e.filters];
          i >= 0 ? a[i].value = l : a.push({
            key: t,
            value: l,
            type: "select"
          }), d("update:filters", a);
          return;
        }
        if (l == null) {
          const i = e.filters.filter((a) => a.key !== t);
          d("update:filters", i);
          return;
        }
        const n = e.filters.findIndex((i) => i.key === t), s = [...e.filters];
        n >= 0 ? s[n].value = l : s.push({
          key: t,
          value: l,
          type: "select"
        }), d("update:filters", s);
      }
    });
    function v() {
      const l = y(), t = e.filters.filter((n) => n.key !== l);
      d("update:filters", t);
    }
    const h = F(!1);
    function b() {
      h.value = !0;
    }
    function k() {
      h.value = !1;
    }
    const x = c(() => (p == null ? void 0 : p.NODE_ENV) === "test" ? !0 : e.header.multiple ? Array.isArray(o.value) && o.value.length > 0 : o.value !== null);
    return (l, t) => {
      var n, s, i, a, u;
      return S(), A("div", I, [
        O(B, {
          modelValue: o.value,
          "onUpdate:modelValue": t[0] || (t[0] = (f) => o.value = f),
          label: e.header.title || "",
          items: m.value,
          clearable: x.value,
          density: ((n = r.inputConfig) == null ? void 0 : n.density) ?? r.density,
          "hide-details": ((s = r.inputConfig) == null ? void 0 : s.hideDetails) ?? r.hideDetails,
          "hide-messages": !0,
          variant: ((i = r.inputConfig) == null ? void 0 : i.variant) ?? r.variant,
          "bg-color": ((a = r.inputConfig) == null ? void 0 : a.backgroundColor) ?? r.backgroundColor,
          "disable-error-handling": ((u = r.inputConfig) == null ? void 0 : u.disableErrorHandling) ?? r.disableErrorHandling,
          multiple: e.header.multiple === !0,
          chips: e.header.chips,
          class: "filter-input",
          "aria-label": e.header.title || "Filtre",
          "onClick:clear": v,
          onFocus: b,
          onBlur: k
        }, null, 8, ["modelValue", "label", "items", "clearable", "density", "hide-details", "variant", "bg-color", "disable-error-handling", "multiple", "chips", "aria-label"])
      ]);
    };
  }
}), H = /* @__PURE__ */ E(N, [["__scopeId", "data-v-674627e0"]]);
export {
  H as default
};
