import { defineComponent as b, computed as h, openBlock as p, createBlock as k } from "vue";
import { aN as C, bf as F } from "./main-CI6Q9nmO.js";
const V = /* @__PURE__ */ b({
  __name: "PeriodFilter",
  props: {
    header: {
      type: Object,
      required: !0
    },
    filters: {
      type: Array,
      default: () => []
    },
    filterValue: {
      type: Object,
      default: () => ({ from: null, to: 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(e, { emit: y }) {
    const l = e, o = y;
    function u() {
      var r, t, i;
      return String(((r = l.header) == null ? void 0 : r.key) || ((t = l.header) == null ? void 0 : t.value) || ((i = l.header) != null && i.title ? `filter_${l.header.title}` : `filter_${Date.now()}`));
    }
    const f = h({
      get: () => l.filterValue,
      set: (r) => {
        try {
          const t = u();
          if (!t) return;
          if (!r) {
            const i = l.filters.filter((a) => a.key !== t);
            o("update:filters", i);
            return;
          }
          if (typeof r == "object" && r.from === null && r.to === null) {
            const i = l.filters.filter((a) => a.key !== t);
            o("update:filters", i);
            return;
          }
          if (typeof r == "object") {
            const i = {
              from: r.from,
              to: r.to
            }, a = l.filters.findIndex((d) => d.key === t), n = [...l.filters];
            a >= 0 ? n[a].value = i : n.push({
              key: t,
              value: i,
              type: "period"
            }), o("update:filters", n);
          }
        } catch (t) {
          console.error("Erreur dans la mise à jour du filtre de période:", t);
        }
      }
    });
    function g() {
      const r = u(), t = l.filters.filter((i) => i.key !== r);
      o("update:filters", t);
    }
    return (r, t) => {
      var i, a, n, d, s, c;
      return p(), k(C, {
        modelValue: f.value,
        "onUpdate:modelValue": t[0] || (t[0] = (m) => f.value = m),
        label: e.header.title,
        clearable: ((i = e.inputConfig) == null ? void 0 : i.clearable) ?? e.clearable,
        density: ((a = e.inputConfig) == null ? void 0 : a.density) ?? e.density,
        "hide-details": ((n = e.inputConfig) == null ? void 0 : n.hideDetails) ?? e.hideDetails,
        "hide-messages": e.header.hideMessages,
        variant: ((d = e.inputConfig) == null ? void 0 : d.variant) ?? e.variant,
        "disable-error-handling": ((s = e.inputConfig) == null ? void 0 : s.disableErrorHandling) ?? e.disableErrorHandling,
        "bg-color": ((c = e.inputConfig) == null ? void 0 : c.backgroundColor) ?? e.backgroundColor,
        format: e.header.dateFormat,
        class: "filter-input",
        "onClick:clear": g
      }, null, 8, ["modelValue", "label", "clearable", "density", "hide-details", "hide-messages", "variant", "disable-error-handling", "bg-color", "format"]);
    };
  }
}), x = /* @__PURE__ */ F(V, [["__scopeId", "data-v-49b093ac"]]);
export {
  x as default
};
