import { defineComponent as N, resolveComponent as x, createBlock as v, openBlock as h, normalizeClass as q, withCtx as E, createCommentVNode as R, createElementVNode as M, toDisplayString as G, renderSlot as H, mergeModels as I, useModel as P, ref as L, watch as F, computed as K, createElementBlock as J, unref as p, createVNode as A } from "vue";
import { d as f, a as Q, C as w, U as Z } from "./app-dOrzXjgr.js";
import { detectLocale as k } from "@feedmepos/mf-common";
import { u as ee } from "./_plugin-vue_export-helper-onplcgja.js";
import { storeToRefs as ae } from "pinia";
const te = new RegExp("([\\p{Ll}\\d])(\\p{Lu})", "gu"), re = new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])", "gu"), ne = new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d", "u"), le = /[^\p{L}\d]+/giu, z = "$1\0$2", O = "";
function V(a) {
  let e = a.trim();
  e = e.replace(te, z).replace(re, z), e = e.replace(le, "\0");
  let t = 0, r = e.length;
  for (; e.charAt(t) === "\0"; )
    t++;
  if (t === r)
    return [];
  for (; e.charAt(r - 1) === "\0"; )
    r--;
  return e.slice(t, r).split(/\0/g);
}
function ce(a) {
  const e = V(a);
  for (let t = 0; t < e.length; t++) {
    const r = e[t], n = ne.exec(r);
    if (n) {
      const c = n.index + (n[1] ?? n[2]).length;
      e.splice(t, 1, r.slice(0, c), r.slice(c));
    }
  }
  return e;
}
function ve(a, e) {
  const [t, r, n] = T(a, e), c = $(e == null ? void 0 : e.locale), s = S(e == null ? void 0 : e.locale), l = e != null && e.mergeAmbiguousCharacters ? b(c, s) : W(c, s);
  return t + r.map((d, u) => u === 0 ? c(d) : l(d, u)).join((e == null ? void 0 : e.delimiter) ?? "") + n;
}
function pe(a, e) {
  const [t, r, n] = T(a, e), c = $(e == null ? void 0 : e.locale), s = S(e == null ? void 0 : e.locale), l = e != null && e.mergeAmbiguousCharacters ? b(c, s) : W(c, s);
  return t + r.map(l).join((e == null ? void 0 : e.delimiter) ?? "") + n;
}
function Ce(a, e) {
  const [t, r, n] = T(a, e), c = $(e == null ? void 0 : e.locale), s = S(e == null ? void 0 : e.locale);
  return t + r.map(b(c, s)).join((e == null ? void 0 : e.delimiter) ?? " ") + n;
}
function xe(a, e) {
  const [t, r, n] = T(a, e), c = $(e == null ? void 0 : e.locale), s = S(e == null ? void 0 : e.locale), l = b(c, s);
  return t + r.map((d, u) => u === 0 ? l(d) : c(d)).join((e == null ? void 0 : e.delimiter) ?? " ") + n;
}
function $(a) {
  return a === !1 ? (e) => e.toLowerCase() : (e) => e.toLocaleLowerCase(a);
}
function S(a) {
  return a === !1 ? (e) => e.toUpperCase() : (e) => e.toLocaleUpperCase(a);
}
function b(a, e) {
  return (t) => `${e(t[0])}${a(t.slice(1))}`;
}
function W(a, e) {
  return (t, r) => {
    const n = t[0];
    return (r > 0 && n >= "0" && n <= "9" ? "_" + n : e(n)) + a(t.slice(1));
  };
}
function T(a, e = {}) {
  const t = e.split ?? (e.separateNumbers ? ce : V), r = e.prefixCharacters ?? O, n = e.suffixCharacters ?? O;
  let c = 0, s = a.length;
  for (; c < a.length; ) {
    const l = a.charAt(c);
    if (!r.includes(l))
      break;
    c++;
  }
  for (; s > c; ) {
    const l = s - 1, d = a.charAt(l);
    if (!n.includes(d))
      break;
    s = l;
  }
  return [
    a.slice(0, c),
    t(a.slice(c, s)),
    a.slice(s)
  ];
}
var C = /* @__PURE__ */ ((a) => (a.Year = "YEAR", a.Month = "MONTH", a.Week = "WEEK", a.Day = "DAY", a))(C || {}), se = /* @__PURE__ */ ((a) => (a.Yesterday = "YESTERDAY", a.Today = "TODAY", a))(se || {});
function Re(a, e = 100) {
  let t = null;
  const r = function(...n) {
    return t && clearTimeout(t), new Promise((c) => {
      t = setTimeout(() => {
        t = null;
        const s = a(...n);
        c(s);
      }, e);
    });
  };
  return r.cancel = () => {
    t && (clearTimeout(t), t = null);
  }, r;
}
function ue() {
  return [...Array(12).keys()].map((a) => f().month(a).format("MMM"));
}
function $e(a, e, t = "") {
  const r = (l) => /^[\x00-\x7F]*$/.test(l) ? " " : "", n = (l) => /^每年/.test(l), c = (l) => /^每周|^每週/.test(l), s = (l) => /^每月/.test(l);
  switch (a.type) {
    case C.Day:
      return e("report.schedule.everyDay");
    case C.Week: {
      const l = e("report.schedule.everyWeek"), d = c(l);
      let u = `${l}${r(l)}`;
      const o = [
        e("report.days.sunday"),
        e("report.days.monday"),
        e("report.days.tuesday"),
        e("report.days.wednesday"),
        e("report.days.thursday"),
        e("report.days.friday"),
        e("report.days.saturday")
      ];
      if (a.days)
        for (let i = 0; i < a.days.length; i++) {
          const Y = d ? o[a.days[i]].replace(/^[周週]/, "") : o[a.days[i]];
          u = u + Y + (i !== a.days.length - 1 ? "," : "");
        }
      return u;
    }
    case C.Month: {
      const l = e("report.schedule.everyMonth"), d = s(l);
      let u = `${l}${r(l)}`;
      return a.days && (u = u + (d ? a.days.map((o) => `${o}日`).join(",") : a.days.join(","))), u;
    }
    case C.Year: {
      if (!a.months && !a.days)
        return e("report.schedule.customDate");
      const l = e("report.schedule.everyYear"), d = n(l);
      let u = `${l}${d ? " " : r(l)}`;
      if (a.months) {
        const o = ue();
        u = u + a.months.map((i) => o[i - 1]).join(",");
      }
      return a.months && a.days && (u = d ? `${u} 的 ` : `${u} ${e("report.common.and")} `), a.days && (u = u + (d ? a.days.map((o) => `${o}日`).join(",") : a.days.join(","))), u;
    }
    default:
      return t;
  }
}
function _(a = {
  startDate: null,
  endDate: null,
  locale: "en-US",
  timezone: void 0
}) {
  if (!a.startDate || !a.endDate)
    return "No comparison";
  let e = f().subtract(1, "day").endOf("day"), t = f().endOf("day");
  return a.startDate && (e = a.timezone ? f(a.startDate).tz(a.timezone).locale(a.locale) : f(a.startDate).locale(a.locale)), a.endDate && (t = a.timezone ? f(a.endDate).tz(a.timezone).locale(a.locale) : f(a.endDate).locale(a.locale)), e.format("YYYY") !== t.format("YYYY") ? `${e.format("DD MMM YYYY")} - ${t.format("DD MMM YYYY")}` : `${e.format("DD MMM")} - ${t.format("DD MMM YYYY")}`;
}
function Se(a = {
  startTime: null,
  endTime: null,
  locale: "en-US"
}) {
  const e = "hh:mmA", { startTime: t, endTime: r, locale: n } = a;
  if (!t || !r) return "";
  const c = f().set("hour", t.hour).set("minute", t.minute).locale(n), s = f().set("hour", r.hour).set("minute", r.minute).locale(n);
  return `${c.format(e)}-${s.format(e)}`;
}
const de = { class: "fm-typo-en-body-md-600 flex items-center gap-1 flex-1 min-w-0" }, oe = { class: "text-ellipsis overflow-hidden whitespace-nowrap flex-1 min-w-0" }, me = { class: "whitespace-nowrap flex-none" }, U = /* @__PURE__ */ N({
  __name: "FilterChip",
  props: {
    label: {
      type: String,
      default: ""
    },
    leftIcon: {
      type: String,
      default: ""
    },
    rightIcon: {
      type: String,
      default: ""
    },
    trailingIcon: {
      type: String,
      default: ""
    },
    loading: {
      type: Boolean,
      default: !1
    }
  },
  setup(a) {
    const e = a;
    return (t, r) => {
      const n = x("FmIcon"), c = x("FmCircularProgress"), s = x("FmChip");
      return h(), v(s, {
        "aria-busy": e.loading,
        class: q([
          "bg-fm-color-neutral-gray-100 text-fm-color-neutral-gray-400 max-w-[400px] flex items-center gap-1 transition-opacity",
          e.loading && "opacity-80"
        ])
      }, {
        default: E(() => [
          a.leftIcon ? (h(), v(n, {
            key: 0,
            name: e.leftIcon,
            size: "sm",
            outline: "",
            class: "flex-none"
          }, null, 8, ["name"])) : R("", !0),
          M("div", de, [
            M("span", oe, G(e.label), 1),
            a.rightIcon ? (h(), v(n, {
              key: 0,
              name: a.rightIcon,
              size: "sm",
              outline: "",
              class: "flex-none"
            }, null, 8, ["name"])) : R("", !0),
            M("span", me, [
              H(t.$slots, "default")
            ]),
            e.loading ? (h(), v(c, {
              key: 1,
              size: "md",
              class: "flex-none scale-75"
            })) : a.trailingIcon ? (h(), v(n, {
              key: 2,
              name: a.trailingIcon,
              size: "sm",
              outline: "",
              class: "flex-none"
            }, null, 8, ["name"])) : R("", !0)
          ])
        ]),
        _: 3
      }, 8, ["aria-busy", "class"]);
    };
  }
}), fe = { class: "flex gap-2 items-center" }, j = "YYYY-MM-DD", be = /* @__PURE__ */ N({
  __name: "DateRangeSelect",
  props: /* @__PURE__ */ I({
    compare: {
      type: Boolean,
      default: !1
    },
    datePredefinedRanges: {
      type: Array,
      default: () => Z()
    },
    label: {
      type: String,
      required: !1,
      default: null
    },
    removable: {
      type: Boolean,
      required: !1,
      default: !1
    }
  }, {
    compareType: {
      type: String,
      default: w.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__ */ I(["update", "chip-closed"], ["update:compareType", "update:dateRange", "update:compareDateRange"]),
  setup(a, { emit: e }) {
    const { t, locale: r } = ee();
    function n(m) {
      return m ? m.includes("T") ? f(m).tz(u.value).format(j) : f(m).format(j) : null;
    }
    const c = e, s = P(a, "compareType"), l = P(a, "dateRange"), d = P(a, "compareDateRange"), { timezone: u } = ae(Q()), o = L({
      startDate: n(l.value.startDate),
      endDate: n(l.value.endDate)
    }), i = L({
      startDate: d.value.startDate ? n(d.value.startDate) : null,
      endDate: d.value.endDate ? n(d.value.endDate) : null
    });
    F(
      [() => o.value],
      () => {
        o.value.endDate || (o.value.endDate = o.value.startDate);
        const m = {
          startDate: f.tz(o.value.startDate, u.value).startOf("day").utc().toISOString(),
          endDate: f.tz(o.value.endDate, u.value).endOf("day").utc().toISOString()
        };
        l.value = m, c("update", m);
      },
      { deep: !0 }
    ), F([() => i.value], () => {
      const m = i.value.startDate, y = i.value.endDate, g = m ? f(
        m instanceof Date ? m : f(m).toDate()
      ).startOf("day").tz(u.value, !0).toISOString() : void 0, D = y ? f(y instanceof Date ? y : f(y).toDate()).tz(u.value, !0).endOf("day").toISOString() : void 0;
      d.value = {
        startDate: g,
        endDate: D
      };
    });
    function Y(m) {
      s.value = m;
    }
    function B(m) {
      c("chip-closed", m);
    }
    const X = K(() => {
      const m = k(), y = m.startsWith("zh") ? "" : " ", g = t("report.common.comparedTo"), D = _({
        startDate: i.value.startDate ?? null,
        endDate: i.value.endDate ?? null,
        locale: m
      });
      return s.value === w.NO_COMPARISON ? `${g}: ${t(`report.compare.${s.value}`)}` : s.value === w.CUSTOM ? `${g}: ${D}` : `${g}${y}${t(`report.compare.${s.value}`).toLowerCase()}: ${D}`;
    });
    return (m, y) => {
      const g = x("FmSimpleDateRangePicker");
      return h(), J("div", fe, [
        (h(), v(g, {
          key: `date-picker-${p(r)}`,
          modelValue: o.value,
          "onUpdate:modelValue": y[1] || (y[1] = (D) => o.value = D),
          "show-predefined-range": "",
          "predefined-range": a.datePredefinedRanges.map((D) => ({
            ...D,
            label: p(t)(`report.date.${D.label}`)
          })),
          class: "w-2/6"
        }, {
          "trigger-button": E(() => [
            A(U, {
              "left-icon": a.label ? "filter_alt" : "calendar_month",
              label: a.label ?? p(_)({
                startDate: o.value.startDate ?? "",
                endDate: o.value.endDate ?? "",
                locale: p(k)()
              }),
              removable: a.removable,
              onChipClosed: y[0] || (y[0] = (D) => B(!0))
            }, null, 8, ["left-icon", "label", "removable"])
          ]),
          _: 1
        }, 8, ["modelValue", "predefined-range"])),
        a.compare ? (h(), v(g, {
          key: `compare-date-picker-${p(r)}`,
          modelValue: i.value,
          "onUpdate:modelValue": y[2] || (y[2] = (D) => i.value = D),
          "compare-type": s.value,
          "onUpdate:compareType": y[3] || (y[3] = (D) => s.value = D),
          "show-predefined-range": "",
          "compare-target": o.value,
          "default-compare-type": s.value,
          onSelectComparison: Y
        }, {
          "trigger-button": E(() => [
            A(U, { label: X.value }, null, 8, ["label"])
          ]),
          _: 1
        }, 8, ["modelValue", "compare-type", "compare-target", "default-compare-type"])) : R("", !0)
      ]);
    };
  }
});
export {
  C,
  be as _,
  ve as a,
  se as b,
  Ce as c,
  Re as d,
  $e as e,
  U as f,
  ue as g,
  Se as h,
  _ as i,
  pe as p,
  xe as s
};
