import { defineComponent as P, resolveComponent as b, createBlock as D, openBlock as i, withCtx as R, createCommentVNode as S, createElementVNode as V, toDisplayString as E, renderSlot as N, mergeModels as k, useModel as v, ref as x, watch as F, createElementBlock as Y, createVNode as y, unref as u } from "vue";
import { u as j, d as o, N as U, C as q } from "./vue-i18n-DG0DIzwC.js";
import { d as T } from "./helper-C0VLdBRU.js";
import { detectLocale as M } from "@feedmepos/mf-common";
const z = { class: "fm-typo-en-body-md-600 text-ellipsis overflow-hidden whitespace-nowrap" }, _ = { class: "fm-typo-en-body-md-600 text-ellipsis overflow-hidden whitespace-nowrap" }, O = /* @__PURE__ */ P({
  __name: "FilterChip",
  props: {
    label: {
      type: String,
      default: ""
    },
    leftIcon: {
      type: String,
      default: ""
    },
    rightIcon: {
      type: String,
      default: ""
    }
  },
  setup(e) {
    const c = e;
    return (p, g) => {
      const d = b("FmIcon"), m = b("FmChip");
      return i(), D(m, { class: "bg-fm-color-neutral-gray-100 text-fm-color-neutral-gray-400 max-w-fit" }, {
        default: R(() => [
          e.leftIcon ? (i(), D(d, {
            key: 0,
            name: c.leftIcon,
            size: "sm",
            outline: ""
          }, null, 8, ["name"])) : S("", !0),
          V("p", z, E(c.label), 1),
          e.rightIcon ? (i(), D(d, {
            key: 1,
            name: e.rightIcon,
            size: "sm",
            outline: ""
          }, null, 8, ["name"])) : S("", !0),
          V("div", _, [
            N(p.$slots, "default")
          ])
        ]),
        _: 3
      });
    };
  }
}), A = { class: "flex gap-2 items-center" }, f = "YYYY-MM-DD", K = /* @__PURE__ */ P({
  __name: "DateRangeSelect",
  props: /* @__PURE__ */ k({
    compare: {
      type: Boolean,
      default: !1
    },
    datePredefinedRanges: {
      type: Array,
      default: () => U
    },
    label: {
      type: String,
      required: !1,
      default: null
    },
    removable: {
      type: Boolean,
      required: !1,
      default: !1
    }
  }, {
    compareType: {
      type: String,
      default: q.PRECEDING_PERIOD
    },
    compareTypeModifiers: {},
    dateRange: {
      type: Object,
      default: () => ({
        startDate: void 0,
        endDate: void 0
      })
    },
    dateRangeModifiers: {},
    compareDateRange: {
      type: Object,
      default: () => ({
        startDate: void 0,
        endDate: void 0
      })
    },
    compareDateRangeModifiers: {}
  }),
  emits: /* @__PURE__ */ k(["update", "chip-closed"], ["update:compareType", "update:dateRange", "update:compareDateRange"]),
  setup(e, { emit: c }) {
    var C, h, I;
    const { t: p } = j(), g = c, d = v(e, "compareType"), m = v(e, "dateRange"), s = v(e, "compareDateRange"), t = x({
      startDate: (C = o(m.value.startDate)) == null ? void 0 : C.local().format(f),
      endDate: (h = o(m.value.endDate)) == null ? void 0 : h.local().format(f)
    }), a = x({
      startDate: s.value.startDate ? (I = o(s.value.startDate)) == null ? void 0 : I.local().format(f) : null,
      endDate: s.value.endDate ? o(s.value.endDate).local().format(f) : null
    });
    F(
      [() => t.value],
      () => {
        t.value.endDate || (t.value.endDate = t.value.startDate);
        const r = {
          startDate: o(t.value.startDate).toISOString(),
          endDate: o(t.value.endDate).toISOString()
        };
        m.value = r, g("update", r);
      },
      { deep: !0 }
    ), F([() => a.value], () => {
      s.value = {
        startDate: a.value.startDate ? o(a.value.startDate).toISOString() : void 0,
        endDate: a.value.endDate ? o(a.value.endDate).toISOString() : void 0
      };
    });
    function $(r) {
      d.value = r;
    }
    function B(r) {
      g("chip-closed", r);
    }
    return (r, l) => {
      const w = b("FmSimpleDateRangePicker");
      return i(), Y("div", A, [
        y(w, {
          modelValue: t.value,
          "onUpdate:modelValue": l[1] || (l[1] = (n) => t.value = n),
          "show-predefined-range": "",
          "predefined-range": e.datePredefinedRanges.map((n) => ({
            ...n,
            label: u(p)(`report.date.${n.label}`)
          })),
          class: "w-2/6"
        }, {
          "trigger-button": R(() => [
            y(O, {
              "left-icon": e.label ? "filter_alt" : "calendar_month",
              label: e.label ?? u(T)({
                startDate: t.value.startDate ?? "",
                endDate: t.value.endDate ?? "",
                locale: u(M)()
              }),
              removable: e.removable,
              onChipClosed: l[0] || (l[0] = (n) => B(!0))
            }, null, 8, ["left-icon", "label", "removable"])
          ]),
          _: 1
        }, 8, ["modelValue", "predefined-range"]),
        e.compare ? (i(), D(w, {
          key: 0,
          modelValue: a.value,
          "onUpdate:modelValue": l[2] || (l[2] = (n) => a.value = n),
          "compare-type": d.value,
          "onUpdate:compareType": l[3] || (l[3] = (n) => d.value = n),
          "show-predefined-range": "",
          "compare-target": t.value,
          onSelectComparison: $
        }, {
          "trigger-button": R(() => [
            y(O, {
              label: `${u(p)("report.common.compare")}: ${u(T)({
                startDate: a.value.startDate ?? null,
                endDate: a.value.endDate ?? null,
                locale: u(M)()
              })}`
            }, null, 8, ["label"])
          ]),
          _: 1
        }, 8, ["modelValue", "compare-type", "compare-target"])) : S("", !0)
      ]);
    };
  }
});
export {
  K as _,
  O as a
};
