import { defineComponent as A, resolveComponent as S, createBlock as p, openBlock as y, withCtx as T, createCommentVNode as R, createElementVNode as M, toDisplayString as j, renderSlot as B, mergeModels as k, useModel as b, ref as C, watch as x, createElementBlock as U, unref as f, createVNode as O } from "vue";
import { d as r, a as W, Y as q, C as G } from "./app-C2vt2B-i.js";
import { detectLocale as E } from "@feedmepos/mf-common";
import { u as H } from "./vue-i18n-DVWuTfed.js";
import { storeToRefs as K } from "pinia";
var v = /* @__PURE__ */ ((e) => (e.Year = "YEAR", e.Month = "MONTH", e.Week = "WEEK", e.Day = "DAY", e))(v || {}), L = /* @__PURE__ */ ((e) => (e.Yesterday = "YESTERDAY", e.Today = "TODAY", e))(L || {});
function le(e, t = 100) {
  let n = null;
  const a = function(...o) {
    return n && clearTimeout(n), new Promise((l) => {
      n = setTimeout(() => {
        n = null;
        const m = e(...o);
        l(m);
      }, t);
    });
  };
  return a.cancel = () => {
    n && (clearTimeout(n), n = null);
  }, a;
}
function J() {
  return [...Array(12).keys()].map((e) => r().month(e).format("MMM"));
}
function oe(e, t, n = "") {
  switch (e.type) {
    case v.Day:
      return t("report.schedule.everyDay");
    case v.Week: {
      let a = `${t("report.schedule.everyWeek")} `;
      const o = [
        t("report.days.sunday"),
        t("report.days.monday"),
        t("report.days.tuesday"),
        t("report.days.wednesday"),
        t("report.days.thursday"),
        t("report.days.friday"),
        t("report.days.saturday")
      ];
      if (e.days)
        for (let l = 0; l < e.days.length; l++)
          a = a + o[e.days[l]] + (l !== e.days.length - 1 ? "," : "");
      return a;
    }
    case v.Month: {
      let a = `${t("report.schedule.everyMonth")} `;
      return e.days && (a = a + e.days.join(",")), a;
    }
    case v.Year: {
      if (!e.months && !e.days)
        return t("report.schedule.customDate");
      let a = `${t("report.schedule.everyYear")} `;
      if (e.months) {
        const o = J();
        a = a + e.months.map((l) => o[l - 1]).join(",");
      }
      return e.months && e.days && (a = a + ` ${t("report.common.and")} `), e.days && (a = a + e.days.join(",")), a;
    }
    default:
      return n;
  }
}
function F(e = {
  startDate: null,
  endDate: null,
  locale: "en-US",
  timezone: void 0
}) {
  if (!e.startDate || !e.endDate)
    return "No comparison";
  let t = r().subtract(1, "day").endOf("day"), n = r().endOf("day");
  return e.startDate && (t = e.timezone ? r(e.startDate).tz(e.timezone).locale(e.locale) : r(e.startDate).locale(e.locale)), e.endDate && (n = e.timezone ? r(e.endDate).tz(e.timezone).locale(e.locale) : r(e.endDate).locale(e.locale)), t.format("YYYY") !== n.format("YYYY") ? `${t.format("DD MMM YYYY")} - ${n.format("DD MMM YYYY")}` : `${t.format("DD MMM")} - ${n.format("DD MMM YYYY")}`;
}
function de(e = {
  startTime: null,
  endTime: null,
  locale: "en-US"
}) {
  const t = "hh:mmA", { startTime: n, endTime: a, locale: o } = e;
  if (!n || !a) return "";
  const l = r().set("hour", n.hour).set("minute", n.minute).locale(o), m = r().set("hour", a.hour).set("minute", a.minute).locale(o);
  return `${l.format(t)}-${m.format(t)}`;
}
const Q = { class: "fm-typo-en-body-md-600 flex items-center gap-1 flex-1 min-w-0" }, X = { class: "text-ellipsis overflow-hidden whitespace-nowrap flex-1 min-w-0" }, Z = { class: "whitespace-nowrap flex-none" }, V = /* @__PURE__ */ A({
  __name: "FilterChip",
  props: {
    label: {
      type: String,
      default: ""
    },
    leftIcon: {
      type: String,
      default: ""
    },
    rightIcon: {
      type: String,
      default: ""
    },
    trailingIcon: {
      type: String,
      default: ""
    }
  },
  setup(e) {
    const t = e;
    return (n, a) => {
      const o = S("FmIcon"), l = S("FmChip");
      return y(), p(l, { class: "bg-fm-color-neutral-gray-100 text-fm-color-neutral-gray-400 max-w-fit flex items-center gap-1" }, {
        default: T(() => [
          e.leftIcon ? (y(), p(o, {
            key: 0,
            name: t.leftIcon,
            size: "sm",
            outline: "",
            class: "flex-none"
          }, null, 8, ["name"])) : R("", !0),
          M("div", Q, [
            M("span", X, j(t.label), 1),
            e.rightIcon ? (y(), p(o, {
              key: 0,
              name: e.rightIcon,
              size: "sm",
              outline: "",
              class: "flex-none"
            }, null, 8, ["name"])) : R("", !0),
            M("span", Z, [
              B(n.$slots, "default")
            ]),
            e.trailingIcon ? (y(), p(o, {
              key: 1,
              name: e.trailingIcon,
              size: "sm",
              outline: "",
              class: "flex-none"
            }, null, 8, ["name"])) : R("", !0)
          ])
        ]),
        _: 3
      });
    };
  }
}), _ = { class: "flex gap-2 items-center" }, Y = "YYYY-MM-DD", ue = /* @__PURE__ */ A({
  __name: "DateRangeSelect",
  props: /* @__PURE__ */ k({
    compare: {
      type: Boolean,
      default: !1
    },
    datePredefinedRanges: {
      type: Array,
      default: () => q()
    },
    label: {
      type: String,
      required: !1,
      default: null
    },
    removable: {
      type: Boolean,
      required: !1,
      default: !1
    }
  }, {
    compareType: {
      type: String,
      default: G.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: t }) {
    var z, I, $, w;
    const { t: n, locale: a } = H(), o = t, l = b(e, "compareType"), m = b(e, "dateRange"), g = b(e, "compareDateRange"), { timezone: i } = K(W()), s = C({
      startDate: m.value.startDate ? (z = r(m.value.startDate)) == null ? void 0 : z.tz(i.value).format(Y) : null,
      endDate: m.value.endDate ? (I = r(m.value.endDate)) == null ? void 0 : I.tz(i.value).format(Y) : null
    }), D = C({
      startDate: g.value.startDate ? ($ = r(g.value.startDate)) == null ? void 0 : $.tz(i.value).format(Y) : null,
      endDate: g.value.endDate ? (w = r(g.value.endDate)) == null ? void 0 : w.tz(i.value).format(Y) : null
    });
    x(
      [() => s.value],
      () => {
        s.value.endDate || (s.value.endDate = s.value.startDate);
        const u = {
          startDate: r.tz(s.value.startDate, i.value).startOf("day").utc().toISOString(),
          endDate: r.tz(s.value.endDate, i.value).endOf("day").utc().toISOString()
        };
        m.value = u, o("update", u);
      },
      { deep: !0 }
    ), x([() => D.value], () => {
      const u = D.value.startDate, d = D.value.endDate, h = u ? r(
        u instanceof Date ? u : r(u).toDate()
      ).startOf("day").tz(i.value, !0).toISOString() : void 0, c = d ? r(d instanceof Date ? d : r(d).toDate()).tz(i.value, !0).endOf("day").toISOString() : void 0;
      g.value = {
        startDate: h,
        endDate: c
      };
    });
    function N(u) {
      l.value = u;
    }
    function P(u) {
      o("chip-closed", u);
    }
    return (u, d) => {
      const h = S("FmSimpleDateRangePicker");
      return y(), U("div", _, [
        (y(), p(h, {
          key: `date-picker-${f(a)}`,
          modelValue: s.value,
          "onUpdate:modelValue": d[1] || (d[1] = (c) => s.value = c),
          "show-predefined-range": "",
          "predefined-range": e.datePredefinedRanges.map((c) => ({
            ...c,
            label: f(n)(`report.date.${c.label}`)
          })),
          class: "w-2/6"
        }, {
          "trigger-button": T(() => [
            O(V, {
              "left-icon": e.label ? "filter_alt" : "calendar_month",
              label: e.label ?? f(F)({
                startDate: s.value.startDate ?? "",
                endDate: s.value.endDate ?? "",
                locale: f(E)()
              }),
              removable: e.removable,
              onChipClosed: d[0] || (d[0] = (c) => P(!0))
            }, null, 8, ["left-icon", "label", "removable"])
          ]),
          _: 1
        }, 8, ["modelValue", "predefined-range"])),
        e.compare ? (y(), p(h, {
          key: `compare-date-picker-${f(a)}`,
          modelValue: D.value,
          "onUpdate:modelValue": d[2] || (d[2] = (c) => D.value = c),
          "compare-type": l.value,
          "onUpdate:compareType": d[3] || (d[3] = (c) => l.value = c),
          "show-predefined-range": "",
          "compare-target": s.value,
          "default-compare-type": l.value,
          onSelectComparison: N
        }, {
          "trigger-button": T(() => [
            O(V, {
              label: `${f(n)("report.common.compare")}: ${f(F)({
                startDate: D.value.startDate ?? null,
                endDate: D.value.endDate ?? null,
                locale: f(E)()
              })}`
            }, null, 8, ["label"])
          ]),
          _: 1
        }, 8, ["modelValue", "compare-type", "compare-target", "default-compare-type"])) : R("", !0)
      ]);
    };
  }
});
export {
  v as C,
  ue as _,
  V as a,
  F as b,
  de as c,
  le as d,
  L as e,
  oe as f,
  J as g
};
