import { computed as y, defineComponent as ee, mergeModels as me, useModel as te, ref as h, onMounted as Se, nextTick as X, watch as J, resolveComponent as V, createElementBlock as N, openBlock as W, Fragment as oe, renderSlot as pe, createVNode as B, normalizeStyle as ne, unref as l, createElementVNode as P, toDisplayString as ze, withCtx as q, createBlock as U, createCommentVNode as he, normalizeClass as Pe, h as bt, renderList as _t, createTextVNode as Kt, onUnmounted as Zt, resolveDynamicComponent as Qt, withDirectives as ea, vShow as ta } from "vue";
import { W as F, d as Ee, v as $e, e as Ye, f as kt, q as aa, R as Fe, g as la } from "./BaseDialog.vue_vue_type_script_setup_true_lang-BNCi01ju.js";
import { u as Me, b as at, a as lt } from "./vue-i18n-CA7n5PbM.js";
import { a as wt } from "./helper-CjlOhf8H.js";
import { storeToRefs as Le, defineStore as oa } from "pinia";
import { a as na } from "./SelectComponent.vue_vue_type_script_setup_true_lang-C6I6eTgv.js";
import { r as xe } from "./i18n-Cif1I9J2.js";
import { _ as xt } from "./NoData.vue_vue_type_script_setup_true_lang-D8TQd5xZ.js";
import { components as sa, useSnackbar as Tt, useBreakpoints as ra } from "@feedmepos/ui-library";
var Je = /* @__PURE__ */ ((e) => (e.line = "LINE", e.bar = "BAR", e))(Je || {}), Z = /* @__PURE__ */ ((e) => (e.top = "TOP", e.bottom = "BOTTOM", e))(Z || {}), Ke = /* @__PURE__ */ ((e) => (e.start = "start", e.center = "center", e.end = "end", e))(Ke || {}), Ze = /* @__PURE__ */ ((e) => (e.start = "start", e.center = "center", e.end = "end", e.left = "left", e.right = "right", e.top = "top", e.bottom = "bottom", e))(Ze || {}), Qe = /* @__PURE__ */ ((e) => (e.top = "top", e.bottom = "bottom", e))(Qe || {}), et = /* @__PURE__ */ ((e) => (e.right = "right", e.left = "left", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.top = "top", e.bottom = "bottom", e.right = "right", e.left = "left", e.chartArea = "chartArea", e))(tt || {});
F.Circular, F.Table, F.BarChart, F.LineChart, F.StackBarChart, F.StackLineChart, F.Scorecard, F.Spacer;
const ia = [
  {
    type: F.Circular,
    showLabel: !1,
    // TODO: temporarily removed show label as it has no function
    showDrillDimension: !0,
    showRollup: !1,
    showSearchBar: !1
  },
  {
    type: F.Table,
    showLabel: !1,
    showDrillDimension: !0,
    showRollup: !0,
    showSearchBar: !0
  },
  {
    type: F.BarChart,
    showLabel: !1,
    // TODO: temporarily removed show label as it has no function
    showDrillDimension: !0,
    showRollup: !1,
    showSearchBar: !1
  },
  {
    type: F.LineChart,
    showLabel: !1,
    // TODO: temporarily removed show label as it has no function
    showDrillDimension: !0,
    showRollup: !0,
    showSearchBar: !1
  },
  {
    type: F.StackBarChart,
    showLabel: !1,
    // TODO: temporarily removed show label as it has no function
    showDrillDimension: !0,
    showRollup: !0,
    showSearchBar: !1
  },
  {
    type: F.StackLineChart,
    showLabel: !1,
    // TODO: temporarily removed show label as it has no function
    showDrillDimension: !0,
    showRollup: !0,
    showSearchBar: !1
  },
  {
    type: F.Scorecard,
    showLabel: !1,
    showDrillDimension: !1,
    showRollup: !1,
    showSearchBar: !1
  },
  {
    type: F.Spacer,
    showLabel: !1,
    showDrillDimension: !1,
    showRollup: !1,
    showSearchBar: !1
  }
];
function Ge(e) {
  const n = [e.schemaName, e.name];
  return "option" in e && e.option && n.push(e.option), "aggregation" in e && e.aggregation && n.push(e.aggregation), n.push(e.label.replace(/[^a-zA-Z0-9]/g, "")), n.join("_").toLowerCase();
}
function ua(e, n) {
  switch (e) {
    case F.BarChart:
    case F.LineChart:
    case F.StackBarChart:
    case F.StackLineChart:
      return Array.isArray(n == null ? void 0 : n.datasets) && Array.isArray(n == null ? void 0 : n.xAxis) && n.datasets.length > 0 && n.xAxis.length > 0;
    case F.Table:
      return Array.isArray(n == null ? void 0 : n.rows) && Array.isArray(n == null ? void 0 : n.columns) && n.rows.length > 0 && n.columns.length > 0;
    case F.Circular:
      return Array.isArray(n == null ? void 0 : n.datasets) && n.datasets.length > 0;
    case F.Scorecard:
      return !0;
    case F.Spacer:
      return !0;
  }
}
const Ct = [
  "54, 162, 235",
  //8CE6D7
  "0, 123, 167",
  //007BA7
  "255, 93, 83",
  //FF5D53
  "115, 200, 230",
  //73C8E6
  "252, 162, 62",
  //FCA23E
  "240, 155, 190",
  //F09BBE
  "255, 210, 50",
  //FFD232
  "80, 190, 155",
  //50BE9B
  "131, 88, 212",
  //8358D4
  "155, 80, 70"
  //9B5046
];
function Q({
  index: e,
  isCompare: n,
  opacity: d
}) {
  let t = typeof d == "number" ? d : 1;
  return n && (t = t * 0.6), `rgba(${Ct[e % Ct.length]}, ${t})`;
}
function Rt(e, n, d) {
  if (e === "" || n === "")
    return null;
  let t = (L) => L == null ? void 0 : L.replace(/,/g, "");
  d === "ID" && (t = (L) => L == null ? void 0 : L.replace(/\./g, "").replace(/,/g, "."));
  const x = Number(t(e)), C = Number(t(n));
  if (isNaN(x) || isNaN(C))
    return null;
  let k = 0;
  C === 0 ? x === 0 ? k = 0 : k = 1 : k = (x - C) / C;
  const z = ca(k);
  return {
    value: isNaN(k) ? "" : `${(k * 100).toFixed(0)}%`,
    icon: z
  };
}
function ca(e) {
  return e > 0 ? {
    name: "moving",
    color: "#1F7735",
    tailwind: "fm-color-system-success-100"
  } : e < 0 ? {
    name: "trending_down",
    color: "#99231D",
    tailwind: "fm-color-system-error-100"
  } : {
    name: "equal",
    color: "#C7C7CC",
    tailwind: "fm-color-neutral-gray-100"
  };
}
function We(e) {
  function n(c, u, r) {
    if (c.measureText(u).width <= r) return u;
    const i = "…";
    let w = 0, p = u.length;
    for (; w < p; ) {
      const f = Math.floor((w + p) / 2), g = u.slice(0, f) + i;
      c.measureText(g).width <= r ? w = f + 1 : p = f;
    }
    return u.slice(0, w - 1) + i;
  }
  const d = y(() => ({
    display: e.showLabel,
    align: e.labelAlign,
    anchor: e.labelAnchor,
    rotation: e.labelRotation,
    offset: e.labelOffset,
    font: {
      size: e.labelFontSize
    },
    color: (c) => {
      const u = c.chart.data.datasets[c.datasetIndex];
      return u.borderColor ? Array.isArray(u.borderColor) ? u.borderColor[c.dataIndex] : u.borderColor : u.backgroundColor ? Array.isArray(u.backgroundColor) ? u.backgroundColor[c.dataIndex] : u.backgroundColor : "#000";
    },
    formatter: (c) => c === 0 ? "" : c.toLocaleString("en-US")
  })), t = y(() => ({
    display: e.showX,
    position: e.xPosition,
    grid: {
      display: e.showXGrid
    },
    ticks: {
      display: e.showXTick,
      callback: function(c) {
        if ((e == null ? void 0 : e.isTransposed) === !0) return String(c);
        let r = String(c);
        const i = this;
        i && typeof i.getLabelForValue == "function" && (r = i.getLabelForValue(c));
        const w = i == null ? void 0 : i.chart, p = i == null ? void 0 : i.ctx, f = w.height * 0.25;
        if (p && f > 0) {
          p.save();
          const E = p.measureText(r).width > f ? n(p, r, f) : r;
          return p.restore(), E;
        }
        return r;
      },
      font: {
        size: e.xTickFontSize
      }
    },
    title: {
      display: e.showXTitle,
      text: e.xTitle,
      font: {
        size: e.xTitleFontSize
      }
    },
    afterBuildTicks: (c) => {
      const u = Array.isArray(c == null ? void 0 : c.ticks) ? c.ticks : [];
      if (u.length === 0) return;
      const r = c.getLabelForValue(u[0].value), i = !isNaN(Number(r));
      c.options.ticks.minRotation = i || u.length < 10 ? 0 : 90;
    },
    afterFit: (c) => {
      if (!(e != null && e.isTransposed)) {
        const u = c.chart.height * 0.4;
        c.height > u && (c.height = u);
      }
    }
  })), x = y(() => ({
    display: e.showY,
    position: e.yPosition,
    grid: {
      display: e.showYGrid
    },
    ticks: {
      display: e.showYTick,
      font: {
        size: e.yTickFontSize
      },
      callback: function(c) {
        if (!((e == null ? void 0 : e.isTransposed) === !0)) return String(c);
        let r = String(c);
        const i = this;
        i && typeof i.getLabelForValue == "function" && (r = i.getLabelForValue(c));
        const w = i == null ? void 0 : i.chart, p = i == null ? void 0 : i.ctx, f = w.width * 0.4;
        if (p && f > 0) {
          p.save();
          const E = p.measureText(r).width > f ? n(p, r, f) : r;
          return p.restore(), E;
        }
        return r;
      }
    },
    title: {
      display: e.showYTitle,
      text: e.yTitle,
      font: {
        size: e.yTitleFontSize
      }
    }
  })), C = y(() => ({
    display: e.showLegend,
    position: e.legendPosition,
    usePointStyle: e.usePointStyle,
    maxHeight: e.legendMaxHeight,
    maxWidth: e.legendMaxWidth,
    labels: {
      usePointStyle: e.usePointStyle ?? !0,
      generateLabels: (c) => {
        var r;
        const u = ((r = c == null ? void 0 : c.data) == null ? void 0 : r.datasets) || [];
        if (u.length === 0) return [];
        if (u.length === 1 && Array.isArray(u[0].backgroundColor) && u[0].backgroundColor.length > 1 && Array.isArray(u[0].data)) {
          const i = u[0];
          return c.data.labels.map((p, f) => {
            const g = i.backgroundColor[f];
            return {
              text: p,
              fontColor: "#6b6b6b",
              fillStyle: g,
              strokeStyle: g,
              datasetIndex: 0,
              index: f,
              hidden: c.getDataVisibility ? !c.getDataVisibility(f) : !1
            };
          });
        }
        return c.data.datasets.map((i, w) => {
          const p = i.borderColor || i.backgroundColor;
          return {
            text: i.label,
            fontColor: "#6b6b6b",
            fillStyle: p,
            strokeStyle: p,
            datasetIndex: w,
            hidden: !c.isDatasetVisible(w)
          };
        });
      }
    }
  })), k = y(() => e.isTransposed), z = y(() => e.chartWidth), L = y(() => e.chartHeight);
  return { datalabels: d, xCfg: t, yCfg: x, isTransposed: k, legend: C, chartWidth: z, chartHeight: L };
}
const da = /* @__PURE__ */ ee({
  __name: "WidgetBarchart",
  props: /* @__PURE__ */ me({
    tileIndex: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const n = e, d = te(e, "modelValue"), t = h(null), x = y(() => {
      var g;
      return ((g = d.value.data) == null ? void 0 : g.xAxis) ?? [];
    }), C = y(() => {
      var g;
      return ((g = d.value.data) == null ? void 0 : g.datasets) ?? [];
    }), { datalabels: k, xCfg: z, yCfg: L, isTransposed: c, legend: u, chartWidth: r, chartHeight: i } = We(
      d.value
    ), w = y(() => C.value.length > 0 ? [
      ...C.value.map((g, E) => ({
        label: g.name,
        data: g.values,
        dash: !!g.isCompare,
        backgroundColor: Q({ index: E, isCompare: g.isCompare })
      }))
    ] : []), p = Ee();
    function f() {
      return p.extractChartSize(t.value, n.tileIndex) || { width: 0, height: 0 };
    }
    return Se(() => {
      X(() => {
        f();
      });
    }), J([w], () => {
      X(() => f());
    }), (g, E) => {
      const m = V("FmBarChart");
      return W(), N(oe, null, [
        pe(g.$slots, "menu"),
        B(m, {
          ref_key: "chartRef",
          ref: t,
          class: "bar-chart",
          datasets: w.value,
          "x-axis": { categories: x.value },
          "x-cfg": l(z),
          "y-cfg": l(L),
          transpose: l(c),
          legend: {
            display: l(u).display ?? !1,
            position: l(u).position,
            maxHeight: l(u).maxHeight,
            maxWidth: l(u).maxWidth,
            labels: l(u).labels
          },
          datalabels: l(k),
          "maintain-aspect-ratio": !1,
          style: ne({
            "--chart-width": l(r) !== void 0 ? l(r) + "px" : "100%",
            "--chart-height": l(i) !== void 0 ? l(i) + "px" : "calc(100% - 36px)"
          })
        }, null, 8, ["datasets", "x-axis", "x-cfg", "y-cfg", "transpose", "legend", "datalabels", "style"])
      ], 64);
    };
  }
}), ha = /* @__PURE__ */ ee({
  __name: "WidgetCircular",
  props: /* @__PURE__ */ me({
    tileIndex: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const n = e, d = te(e, "modelValue"), t = h(null), { datalabels: x, legend: C, chartWidth: k, chartHeight: z } = We(d.value), L = y(() => {
      let r = [];
      return d.value.data.datasets && d.value.data.metrics && d.value.data.datasets.length > 0 && d.value.data.metrics.length > 0 && (r = [
        {
          label: d.value.data.metrics[0],
          data: d.value.data.datasets.map((i) => i.value),
          backgroundColor: d.value.data.datasets.map((i, w) => Q({ index: w }))
        }
      ]), r;
    }), c = Ee();
    function u() {
      return c.extractChartSize(t.value, n.tileIndex) || { width: 0, height: 0 };
    }
    return Se(() => {
      X(() => {
        u();
      });
    }), J([L], () => {
      X(() => u());
    }), (r, i) => {
      const w = V("FmPieChart");
      return W(), N(oe, null, [
        pe(r.$slots, "menu"),
        B(w, {
          ref_key: "chartRef",
          ref: t,
          class: "circular",
          percentage: "70%",
          datasets: L.value,
          metrics: d.value.data.datasets.map((p) => p.name),
          variant: "doughnut",
          legend: {
            display: l(C).display ?? !0,
            position: l(C).position ?? "top",
            maxHeight: l(C).maxHeight ?? 54,
            maxWidth: l(C).maxWidth,
            labels: l(C).labels
          },
          datalabels: l(x),
          "maintain-aspect-ratio": !1,
          style: ne({
            "--chart-width": l(k) !== void 0 ? l(k) + "px" : "100%",
            "--chart-height": l(z) !== void 0 ? l(z) + "px" : "calc(100% - 36px)"
          })
        }, null, 8, ["datasets", "metrics", "legend", "datalabels", "style"])
      ], 64);
    };
  }
}), ma = { class: "flex flex-col gap-1" }, pa = { class: "fm-typo-en-title-sm-600" }, fa = { class: "flex gap-2" }, va = { key: 0 }, ga = { key: 1 }, ya = /* @__PURE__ */ ee({
  __name: "WidgetScorecard",
  props: {
    modelValue: { required: !0 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(e) {
    const n = te(e, "modelValue"), { t: d } = Me(), { compareDateRange: t, defaultDateSetting: x } = Le(at()), { country: C } = lt(), k = y(() => {
      var r;
      return ((r = n.value.data) == null ? void 0 : r.value) || "";
    }), z = y(() => {
      const { data: r } = n.value;
      return r != null && r.comparison ? Rt(k.value, r.comparison, C) : null;
    });
    function L(r) {
      switch (r) {
        case Je.bar:
          return "bar";
        case Je.line:
          return "line";
        default:
          return "line";
      }
    }
    const c = y(() => {
      var r;
      return (r = n.value.data) == null ? void 0 : r.sparkline;
    }), u = y(() => c.value.datasets.map((r) => ({
      label: r.name,
      data: r.values,
      fill: !0,
      color: "#36a2eb"
    })));
    return (r, i) => {
      var E;
      const w = V("FmIcon"), p = V("FmChip"), f = V("FmTooltip"), g = V("FmLineChart");
      return W(), N("div", ma, [
        pe(r.$slots, "menu"),
        P("p", pa, ze(k.value), 1),
        P("div", fa, [
          B(f, {
            content: `vs. ${(E = l(x).defaultCompareType) == null ? void 0 : E.split("_").join(" ")}`,
            placement: "right",
            "hide-arrow": "",
            variant: "plain"
          }, {
            default: q(() => [
              z.value ? (W(), U(p, {
                key: 0,
                icon: z.value.icon.name,
                class: Pe(`bg-${z.value.icon.tailwind}`),
                compact: ""
              }, {
                default: q(() => [
                  B(w, {
                    name: z.value.icon.name,
                    color: z.value.icon.color
                  }, null, 8, ["name", "color"]),
                  P("p", {
                    class: "fm-typo-en-body-md-600",
                    style: ne({ color: z.value.icon.color })
                  }, ze(z.value.value), 5)
                ]),
                _: 1
              }, 8, ["icon", "class"])) : he("", !0),
              l(t).endDate !== null && l(t).startDate !== null && z.value === null ? (W(), U(p, {
                key: 1,
                compact: ""
              }, {
                default: q(() => [
                  B(w, {
                    name: "arrow_upward",
                    color: "#C7C7CC"
                  }),
                  i[0] || (i[0] = P("p", { class: "fm-typo-en-body-md-600 text-fm-color-typo-disabled" }, "N/A", -1))
                ]),
                _: 1
              })) : he("", !0)
            ]),
            _: 1
          }, 8, ["content"])
        ]),
        c.value ? (W(), N("div", va, [
          L(c.value.type) === "line" ? (W(), U(g, {
            key: 0,
            class: "sparkline",
            datasets: u.value,
            legend: {
              display: !1
            },
            datalabels: { display: !1 },
            "x-axis": { categories: c.value.dimensions },
            "y-cfg": { display: !1 },
            "x-cfg": { display: !1 },
            "maintain-aspect-ratio": !1
          }, null, 8, ["datasets", "x-axis"])) : he("", !0)
        ])) : (W(), N("div", ga, i[1] || (i[1] = [
          P("div", { class: "sparkline" }, [
            P("div", { class: "flex flex-col gap-8" }, [
              P("div"),
              P("div")
            ]),
            P("div", { class: "grow" })
          ], -1)
        ])))
      ]);
    };
  }
}), ba = {};
function wa(e, n) {
  const d = V("FmMenuDivider");
  return W(), U(d);
}
const xa = /* @__PURE__ */ na(ba, [["render", wa]]), Ca = "mf-reporttable-dimension", St = oa(Ca, () => {
  const e = h(0), n = h([]), d = h(!1), t = (m, s) => {
    e.value = m, C(m, s);
  }, x = (m, s, b, S) => {
    n[m] = s, n.value = [...n.value], k(m, s, b, S);
  }, C = (m, s) => {
    const b = (s == null ? void 0 : s.querySelectorAll("thead tr")) ?? [], S = (s == null ? void 0 : s.querySelectorAll("tbody tr")) ?? [];
    [...b, ...S].forEach((A) => {
      const o = A;
      o && (o.style.height = `${m}px`);
    });
  }, k = (m, s, b, S = !1) => {
    const _ = (b == null ? void 0 : b.querySelectorAll("th")) ?? [];
    if (m === void 0) return;
    const A = _[m], o = S ? n[m] : s;
    if (!A || o === void 0) return;
    const v = () => {
      A.style.width = `${o}px`;
    };
    S ? requestAnimationFrame(v) : v();
  }, z = () => {
    const m = document.querySelectorAll("th"), s = document.querySelectorAll("td"), b = document.querySelector("table");
    b == null || b.classList.add("table-fixed"), m.forEach((S) => S.classList.add("toggleEditResize")), s.forEach((S) => S.classList.add("toggleEditResize")), d.value = !0;
  }, L = () => {
    const m = document.querySelectorAll("th"), s = document.querySelectorAll("td"), b = document.querySelectorAll(".col-resize-handle"), S = document.querySelectorAll(".row-resize-handle");
    m.forEach((_) => _.classList.remove("toggleEditResize")), s.forEach((_) => _.classList.remove("toggleEditResize")), b.forEach((_) => _.remove()), S.forEach((_) => _.remove()), d.value = !1;
  }, c = () => {
    e.value = 0, n.value = [];
  }, u = (m, s) => {
    if (s) {
      const b = document.querySelectorAll(`thead th:nth-child(${m + 1})`), S = document.querySelectorAll(`tbody td:nth-child(${m + 1})`);
      [...b, ...S].forEach((_) => {
        _.classList.add("highlight-hover-col");
      });
    } else
      document.querySelectorAll(
        `thead th:nth-child(${m + 1}), tbody td:nth-child(${m + 1})`
      ).forEach((b) => b.classList.add("highlight-col"));
  }, r = (m) => {
    const s = document.querySelectorAll("thead tr"), b = document.querySelectorAll("tbody tr"), S = [...s, ...b];
    for (const _ of S)
      m ? _.classList.add("highlight-hover-row") : _.classList.add("highlight-row");
  }, i = (m) => {
    const s = m ? ".highlight-hover-row" : ".highlight-row", b = document.querySelectorAll(s);
    for (const S of b)
      S.classList.remove(s.slice(1));
  }, w = (m) => {
    m ? document.querySelectorAll(".highlight-hover-col").forEach((s) => {
      s.classList.remove("highlight-hover-col");
    }) : document.querySelectorAll(".highlight-col").forEach((s) => s.classList.remove("highlight-col"));
  }, p = (m, s) => {
    const b = /* @__PURE__ */ new Map(), S = m.clientX, _ = m.target.closest("table"), A = _ == null ? void 0 : _.querySelectorAll("th")[s], o = A == null ? void 0 : A.getBoundingClientRect().width, v = b.get(s) ? n[s.toString()] || 60 : (b.set(s, !0), o || n[s.toString()] || 60), R = A == null ? void 0 : A.querySelector("p");
    if (!R) return;
    const T = R.textContent || "", D = window.getComputedStyle(R), H = `${D.fontWeight} ${D.fontSize} ${D.fontFamily}`, O = document.createElement("canvas").getContext("2d");
    if (!O) return;
    O.font = H;
    const G = O.measureText(T), j = window.getComputedStyle(A), Ae = parseFloat(j.paddingLeft || "0"), De = parseFloat(j.paddingRight || "0"), Ve = G.width + Ae + De;
    u(s, !1);
    const _e = (fe) => {
      const se = fe.clientX - S, re = Math.max(Ve, v + se);
      if (_) {
        x(s, re, _, !0);
        let ae = 0;
        _.querySelectorAll("th").forEach((ie, ue) => {
          ae += ue === s ? re : n[ue] || ie.getBoundingClientRect().width;
        }), _.classList.remove("w-full"), _.style.width = `${ae}px`;
        const le = _ == null ? void 0 : _.parentElement;
        if (le) {
          const ie = le.scrollWidth, ue = le.scrollLeft;
          le.offsetWidth + ue >= ie - 100 && (le.scrollLeft = ie);
        }
      }
    }, ke = () => {
      const fe = (_ == null ? void 0 : _.querySelectorAll("th")) ?? [], se = [...n.value];
      fe.forEach((re, ae) => {
        const ve = re.getBoundingClientRect().width;
        n[ae] = ve, se[ae] = ve;
      }), n.value = se, w(!1), document.removeEventListener("mousemove", _e), document.removeEventListener("mouseup", ke);
    };
    document.addEventListener("mousemove", _e), document.addEventListener("mouseup", ke);
  }, f = (m) => {
    const s = m.clientY, b = m.target.closest("table"), S = e.value || 48;
    r(!1);
    const _ = (o) => {
      const v = Math.max(30, S + (o.clientY - s));
      b && t(v, b);
    }, A = () => {
      i(!1), document.removeEventListener("mousemove", _), document.removeEventListener("mouseup", A);
    };
    document.addEventListener("mousemove", _), document.addEventListener("mouseup", A);
  };
  return {
    rowHeight: e,
    colWidths: n,
    isEditing: d,
    updateRowHeight: t,
    updateColWidth: x,
    setRowHeights: C,
    setColWidths: k,
    enableEditMode: z,
    disableEditMode: L,
    resetStore: c,
    highlightCol: u,
    highlightRows: r,
    removeRowHighlight: i,
    removeColHighlight: w,
    resizeCol: p,
    resizeRow: f,
    enableCellResizing: () => {
      const m = document.querySelector("thead"), s = document.querySelectorAll("thead tr"), b = document.querySelectorAll("tbody tr"), S = [...s, ...b];
      m && m.classList.remove("sticky");
      const _ = (A, o) => {
        const v = document.createElement("div");
        return v.className = `${A}-resize-handle`, A === "col" ? (v.addEventListener("mouseenter", () => u(o, !0)), v.addEventListener("mouseleave", () => w(!0)), v.addEventListener("mousedown", (R) => {
          R.stopPropagation(), p(R, o);
        })) : (v.addEventListener("mouseenter", () => r(!0)), v.addEventListener("mouseleave", () => i(!0)), v.addEventListener("mousedown", (R) => {
          R.stopPropagation(), f(R);
        })), v;
      };
      S.forEach((A) => {
        const o = A.closest("thead") !== null;
        A.querySelectorAll(o ? "th" : "td").forEach((R, T) => {
          const D = _("col", T), H = _("row", T);
          R.appendChild(D), R.appendChild(H);
        });
      }), z();
    },
    cancelResizingChanges: () => {
      L();
    }
  };
});
function je(e) {
  if (e == null || e === "")
    return "";
  const n = String(e), d = Number(n);
  if (isNaN(d)) return n;
  const [t, x] = n.split("."), C = new Intl.NumberFormat("en-US").format(Number(t));
  return x !== void 0 ? `${C}.${x}` : C;
}
const Sa = { class: "my-4" }, _a = {
  class: "border-b border-fm-color-neutral-gray-100 hover:bg-fm-color-opacity-sm",
  style: { backgroundColor: "#f9f9f9" }
}, ka = { class: "font-bold" }, Ta = { class: "text-fm-color-neutral-gray-300" }, Ra = /* @__PURE__ */ ee({
  __name: "WidgetTable",
  props: {
    modelValue: { required: !0 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(e) {
    const { t: n, te: d } = Me(), t = te(e, "modelValue"), { country: x } = lt(), { isEditing: C, colWidths: k, rowHeight: z } = Le(St()), { setColWidths: L, setRowHeights: c, enableCellResizing: u } = St(), r = h(null), i = y(() => {
      var o;
      return ((o = t.value.data) == null ? void 0 : o.columns) || [{ label: "", key: "" }];
    }), w = y(() => {
      var o;
      return ((o = t.value.data) == null ? void 0 : o.rows) || [];
    }), p = y(() => t.value.filterText), f = y(() => {
      var o, v;
      if (!(p.value && p.value.trim().length > 0 || !((o = w.value[0]) != null && o.isRollup) && !((v = w.value[w.value.length - 1]) != null && v.isRollup))) {
        if (t.value.rollupPosition === Z.top || t.value.rollupPosition === void 0)
          return Z.top;
        if (t.value.rollupPosition === Z.bottom)
          return Z.bottom;
      }
    }), g = y(() => {
      const T = f.value !== void 0 ? 1 : 0, D = (r.value ? r.value.$el.offsetHeight : 0) - 48;
      return Math.floor((D - 34.5 - 32) / 48) - T;
    }), E = y(() => {
      var v, R;
      let o = [];
      switch (f.value) {
        case Z.top:
          o = [...((v = w.value[0]) == null ? void 0 : v.cells) || []].map((T, D) => {
            var H;
            return {
              main: T,
              comparison: (H = w.value[0]) == null ? void 0 : H.comparisonCells[D],
              rowType: i.value[D].type
            };
          });
          break;
        case Z.bottom:
          o = [...((R = w.value[w.value.length - 1]) == null ? void 0 : R.cells) || []].map((T, D) => {
            var H;
            return {
              main: T,
              comparison: (H = w.value[0]) == null ? void 0 : H.comparisonCells[D],
              rowType: i.value[D].type
            };
          });
          break;
      }
      return o.length > 0 && o[0].main === "" && (o[0].main = "Grand total"), o;
    });
    function m(o) {
      const v = {};
      for (let R = 0; R < i.value.length; R++)
        if (i.value[R].key !== "") {
          const T = o.comparisonCells[R];
          v[i.value[R].key] = {
            main: o.cells[R],
            comparison: T
          }, v.isRollup = o.isRollup;
        }
      return v;
    }
    function s(o) {
      return [...new Array(o < 0 ? 0 : o)].map(() => {
        var R;
        const v = {};
        if ((R = t.value.data) != null && R.columns)
          for (let T = 0; T < t.value.data.columns.length; T++)
            v[t.value.data.columns[T].key] = void 0;
        return v;
      });
    }
    function b(o) {
      let v = (o == null ? void 0 : o.main) || "";
      return v.includes("#") && !v.startsWith("#") && (v = v.split("#")[0]), !o || o.main === "" || o.comparison === "" ? {
        main: v
      } : {
        main: v,
        comparison: o == null ? void 0 : o.comparison,
        difference: Rt(o.main, o.comparison, x)
      };
    }
    const S = y(() => {
      var D, H, Y;
      let o = ((D = t.value.data) == null ? void 0 : D.rows) || [];
      switch (f.value) {
        case Z.bottom:
          o = (H = o[o.length - 1]) != null && H.isRollup ? o.slice(0, -1) : o;
          break;
        case Z.top:
          o = (Y = o[0]) != null && Y.isRollup ? o.slice(1, o.length) : o;
          break;
      }
      const v = o.filter((O) => !(p.value !== "" && (O.isRollup === !0 || !O.cells.some(
        (G) => {
          var j;
          return ((G == null ? void 0 : G.toLowerCase()) || "").includes((j = p.value) == null ? void 0 : j.toLowerCase());
        }
      )))).map((O) => m(O)), R = v.length % g.value;
      let T = 0;
      return R > 0 ? T = Math.abs(R - g.value) : v.length === 0 && (T = g.value), v.push(...s(T)), v;
    }), _ = y(
      () => {
        var o;
        return (((o = t.value.colWidths) == null ? void 0 : o.length) ?? 0) > 0 || k.value.length > 0;
      }
    ), A = y(() => {
      var v;
      let o = [];
      return (v = t.value.data) != null && v.columns && (o = [...t.value.data.columns.map((T) => {
        const D = xe(n, d, T.label, "other");
        return {
          accessorKey: T.key,
          header: () => bt(
            "p",
            {
              class: `w-full ${T.type === "NUMERIC" ? "text-right" : ""} whitespace-nowrap`
            },
            D
          ),
          cell: (H) => {
            var G, j;
            const Y = b(H.getValue()), O = (j = (G = H == null ? void 0 : H.row) == null ? void 0 : G.original) == null ? void 0 : j.isRollup;
            return bt(
              "div",
              {
                class: [
                  O ? "fm-typo-en-body-md-600 text-fm-color-typo-secondary" : "fm-typo-en-body-md-400",
                  T.type === "NUMERIC" ? "text-right" : "",
                  _.value ? "whitespace-normal break-words line-clamp-6" : "whitespace-nowrap"
                ].join(" ")
              },
              [T.type === "NUMERIC" ? je(Y.main) : Y.main]
            );
          },
          enableSorting: !1
        };
      })]), o;
    });
    return J(
      () => k.value.length > 0,
      async (o) => {
        o && C.value && (await X(), u());
      }
    ), J(
      [() => A.value],
      async () => {
        var D;
        await X();
        const o = (D = r.value) == null ? void 0 : D.$el;
        if (!o) return;
        const v = o.querySelector("table");
        if (!v) return;
        v.classList.add(_.value ? "table-fixed" : "table-auto");
        let R, T;
        C.value ? (u(), R = k.value, T = z.value) : (T = t.value.rowHeight, R = t.value.colWidths), typeof T == "number" && c(T, o), R == null || R.forEach((H, Y) => {
          L(Y, H, o);
        });
      },
      { immediate: !0 }
    ), (o, v) => {
      const R = V("FmTable");
      return W(), N(oe, null, [
        P("div", Sa, [
          pe(o.$slots, "menu")
        ]),
        B(R, {
          ref_key: "table",
          ref: r,
          "column-defs": A.value,
          "row-data": S.value,
          "search-value": p.value,
          "page-size": g.value,
          "shrink-at": !1,
          "force-mobile-footer": !0,
          class: "scrollbar-hide-table"
        }, {
          "pin-top": q(() => [
            P("tbody", null, [
              P("tr", _a, [
                (W(!0), N(oe, null, _t(E.value, (T, D) => (W(), N("td", {
                  key: `${l($e)()}_${D}`,
                  class: "h-[48px] text-fm-color-typo-primary px-16"
                }, [
                  P("span", {
                    class: Pe([
                      "items-center text-fm-color-typo-secondary gap-2",
                      T.rowType === "NUMERIC" ? "text-right" : "",
                      _.value ? "whitespace-normal break-words line-clamp-6" : "whitespace-nowrap"
                    ])
                  }, [
                    P("p", ka, ze(T.rowType === "NUMERIC" ? l(je)(T.main) : T.main), 1),
                    P("p", Ta, ze(T.comparison ? T.rowType === "NUMERIC" ? `(${l(je)(T.comparison)})` : `(${T.comparison})` : ""), 1)
                  ], 2)
                ]))), 128))
              ])
            ])
          ]),
          _: 1
        }, 8, ["column-defs", "row-data", "search-value", "page-size"])
      ], 64);
    };
  }
}), Fa = /* @__PURE__ */ ee({
  __name: "WidgetStackBarChart",
  props: /* @__PURE__ */ me({
    tileIndex: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const n = e, d = te(e, "modelValue"), t = h(null), x = y(() => {
      var E;
      return ((E = d.value.data) == null ? void 0 : E.xAxis) || [];
    }), C = y(() => {
      var g;
      return ((g = d.value.data) == null ? void 0 : g.datasets) ?? [];
    }), { datalabels: k, xCfg: z, yCfg: L, isTransposed: c, legend: u, chartWidth: r, chartHeight: i } = We(
      d.value
    ), w = y(() => C.value.length > 0 ? [
      ...C.value.map((g, E) => {
        let m = g.values;
        return {
          label: g.name,
          data: m,
          dash: !!g.isCompare,
          backgroundColor: Q({ index: E, isCompare: g.isCompare })
        };
      })
    ] : []), p = Ee();
    function f() {
      return p.extractChartSize(t.value, n.tileIndex) || { width: 0, height: 0 };
    }
    return Se(() => {
      X(() => {
        f();
      });
    }), J([w], () => {
      X(() => f());
    }), (g, E) => {
      const m = V("FmBarChart");
      return W(), N(oe, null, [
        pe(g.$slots, "menu"),
        B(m, {
          ref_key: "chartRef",
          ref: t,
          class: "bar-chart",
          datasets: w.value,
          "x-axis": { categories: x.value },
          "x-cfg": l(z),
          "y-cfg": l(L),
          transpose: l(c),
          stacked: !0,
          legend: {
            display: l(u).display ?? !1,
            position: l(u).position,
            maxHeight: l(u).maxHeight,
            maxWidth: l(u).maxWidth,
            labels: l(u).labels
          },
          datalabels: l(k),
          "maintain-aspect-ratio": !1,
          style: ne({
            "--chart-width": l(r) !== void 0 ? l(r) + "px" : "100%",
            "--chart-height": l(i) !== void 0 ? l(i) + "px" : "calc(100% - 36px)"
          })
        }, null, 8, ["datasets", "x-axis", "x-cfg", "y-cfg", "transpose", "legend", "datalabels", "style"])
      ], 64);
    };
  }
}), za = /* @__PURE__ */ ee({
  __name: "WidgetStackLineChart",
  props: /* @__PURE__ */ me({
    tileIndex: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    var m;
    const n = e, d = te(e, "modelValue"), t = ((m = d.value.data) == null ? void 0 : m.xAxis) ?? [], x = y(
      () => t.length === 1 && z.value.length > 0 && z.value.every((s) => s.values.length === 1)
    ), C = y(() => x.value ? ["", t[0], ""] : t), k = h(null), z = y(() => {
      var s;
      return ((s = d.value.data) == null ? void 0 : s.datasets) ?? [];
    }), { datalabels: L, xCfg: c, yCfg: u, isTransposed: r, legend: i, chartWidth: w, chartHeight: p } = We(
      d.value
    ), f = y(() => z.value.length > 0 ? [
      ...z.value.map((s, b) => {
        let S = s.values;
        return x.value && (S = [NaN, S[0], NaN]), {
          label: s.name,
          data: S,
          dash: s.isCompare,
          fill: !1,
          color: Q({ index: b, isCompare: s.isCompare }),
          pointRadius: x.value ? 4 : void 0,
          pointHoverRadius: x.value ? 6 : void 0,
          pointBackgroundColor: x.value ? Q({ index: b, isCompare: s.isCompare }) : void 0,
          pointBorderColor: x.value ? Q({ index: b, isCompare: s.isCompare }) : void 0,
          pointBorderWidth: x.value ? 2 : void 0
        };
      })
    ] : []), g = Ee();
    function E() {
      return g.extractChartSize(k.value, n.tileIndex) || { width: 0, height: 0 };
    }
    return Se(() => {
      X(() => {
        E();
      });
    }), J([f], () => {
      X(() => E());
    }), (s, b) => {
      const S = V("FmLineChart");
      return W(), N(oe, null, [
        pe(s.$slots, "menu"),
        B(S, {
          ref_key: "chartRef",
          ref: k,
          class: "line-chart",
          datasets: f.value,
          "x-axis": { categories: C.value },
          "x-cfg": l(c),
          "y-cfg": l(u),
          transpose: l(r),
          legend: {
            display: l(i).display ?? !1,
            position: l(i).position,
            maxHeight: l(i).maxHeight,
            maxWidth: l(i).maxWidth,
            labels: l(i).labels
          },
          stacked: !0,
          datalabels: l(L),
          "maintain-aspect-ratio": !1,
          style: ne({
            "--chart-width": l(w) !== void 0 ? l(w) + "px" : "100%",
            "--chart-height": l(p) !== void 0 ? l(p) + "px" : "calc(100% - 36px)"
          })
        }, null, 8, ["datasets", "x-axis", "x-cfg", "y-cfg", "transpose", "legend", "datalabels", "style"])
      ], 64);
    };
  }
}), Ce = [
  "col-span-1",
  "col-span-2",
  "col-span-3",
  "col-span-4",
  "col-span-5",
  "col-span-6",
  "col-span-7",
  "col-span-8",
  "col-span-9",
  "col-span-10",
  "col-span-11",
  "col-span-12"
];
function La(e) {
  return e < 12 ? Ce[e - 1] : Ce[11];
}
function Ea(e) {
  return e < 12 ? Ce[Math.min(11, e * 2 - 1)] : Ce[11];
}
function Wa(e) {
  return e < 12 ? Ce[Math.min(11, e * 3 - 1)] : Ce[11];
}
const Aa = /* @__PURE__ */ ee({
  __name: "WidgetLinechart",
  props: /* @__PURE__ */ me({
    tileIndex: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    var m;
    const n = e, d = te(e, "modelValue"), t = ((m = d.value.data) == null ? void 0 : m.xAxis) ?? [], x = y(
      () => t.length === 1 && z.value.length > 0 && z.value.every((s) => s.values.length === 1)
    ), C = y(() => x.value ? ["", t[0], ""] : t), k = h(null), z = y(() => {
      var s;
      return ((s = d.value.data) == null ? void 0 : s.datasets) ?? [];
    }), { datalabels: L, xCfg: c, yCfg: u, isTransposed: r, legend: i, chartWidth: w, chartHeight: p } = We(
      d.value
    ), f = y(() => z.value.length > 0 ? [
      ...z.value.map((s, b) => {
        let S = s.values;
        return x.value && (S = [NaN, S[0], NaN]), {
          label: s.name,
          data: S,
          dash: !!s.isCompare,
          fill: !1,
          color: Q({ index: b, isCompare: s.isCompare }),
          pointRadius: x.value ? 4 : void 0,
          pointHoverRadius: x.value ? 6 : void 0,
          pointBackgroundColor: x.value ? Q({ index: b, isCompare: s.isCompare }) : void 0,
          pointBorderColor: x.value ? Q({ index: b, isCompare: s.isCompare }) : void 0,
          pointBorderWidth: x.value ? 2 : void 0
        };
      })
    ] : []), g = Ee();
    function E() {
      return g.extractChartSize(k.value, n.tileIndex) || { width: 0, height: 0 };
    }
    return Se(() => {
      X(() => {
        E();
      });
    }), J([f], () => {
      X(() => E());
    }), (s, b) => {
      const S = V("FmLineChart");
      return W(), N(oe, null, [
        pe(s.$slots, "menu"),
        B(S, {
          ref_key: "chartRef",
          ref: k,
          class: "line-chart",
          datasets: f.value,
          "x-axis": { categories: C.value },
          "x-cfg": l(c),
          "y-cfg": l(u),
          transpose: l(r),
          legend: {
            display: l(i).display ?? !1,
            position: l(i).position,
            maxHeight: l(i).maxHeight,
            maxWidth: l(i).maxWidth,
            labels: l(i).labels
          },
          datalabels: l(L),
          "maintain-aspect-ratio": !1,
          style: ne({
            "--chart-width": l(w) !== void 0 ? l(w) + "px" : "100%",
            "--chart-height": l(p) !== void 0 ? l(p) + "px" : "calc(100% - 36px)"
          })
        }, null, 8, ["datasets", "x-axis", "x-cfg", "y-cfg", "transpose", "legend", "datalabels", "style"])
      ], 64);
    };
  }
}), Da = { class: "flex flex-col gap-16" }, Va = { class: "flex flex-row" }, Ha = /* @__PURE__ */ ee({
  __name: "PdfOrientationDialog",
  props: /* @__PURE__ */ me({
    reportType: {},
    index: {}
  }, {
    modelValue: { type: Boolean, required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const { t: n } = Me(), { FmForm: d } = sa, t = e, x = h(), C = te(e, "modelValue"), k = h(!1), z = Tt(), { selectedLocationIds: L, dateRange: c, timeRange: u } = Le(at()), r = h(Ye.PORTRAIT);
    function i() {
      var p;
      (p = x.value) == null || p.validateInputs();
    }
    async function w() {
      k.value = !0;
      try {
        t.index != null && await kt({
          reportType: t.reportType,
          index: t.index,
          orientationTypes: [r.value],
          timeRange: u.value,
          dateRange: c.value,
          locationIds: L.value
        });
      } catch (p) {
        z.open({ message: p.message, type: "error" });
      } finally {
        k.value = !1;
      }
    }
    return (p, f) => {
      const g = V("FmRadio"), E = V("FmRadioGroup"), m = V("FmButton"), s = V("FmDialog");
      return W(), U(s, {
        modelValue: C.value,
        "onUpdate:modelValue": f[2] || (f[2] = (b) => C.value = b),
        overlay: !0,
        "z-index": 10
      }, {
        "dialog-header": q(() => f[3] || (f[3] = [
          Kt("Select Orientation")
        ])),
        default: q(() => [
          B(l(d), {
            ref_key: "form",
            ref: x,
            onValidationSuccess: w
          }, {
            default: q(() => [
              P("div", Da, [
                B(E, {
                  modelValue: r.value,
                  "onUpdate:modelValue": f[0] || (f[0] = (b) => r.value = b)
                }, {
                  default: q(() => [
                    B(g, {
                      value: l(Ye).PORTRAIT,
                      label: l(n)("report.common.portrait")
                    }, null, 8, ["value", "label"]),
                    B(g, {
                      value: l(Ye).LANDSCAPE,
                      label: l(n)("report.common.landscape")
                    }, null, 8, ["value", "label"])
                  ]),
                  _: 1
                }, 8, ["modelValue"])
              ]),
              P("div", Va, [
                f[4] || (f[4] = P("div", { class: "grow" }, null, -1)),
                B(m, {
                  label: l(n)("report.common.cancel"),
                  variant: "tertiary",
                  onClick: f[1] || (f[1] = (b) => C.value = !1)
                }, null, 8, ["label"]),
                P("div", null, [
                  B(m, {
                    label: l(n)("report.common.download"),
                    loading: k.value,
                    onClick: i
                  }, null, 8, ["label", "loading"])
                ])
              ])
            ]),
            _: 1
          }, 512)
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), Ba = {
  key: 1,
  class: "grow"
}, $a = {
  key: 2,
  class: "flex"
}, Ga = /* @__PURE__ */ ee({
  __name: "DynamicWidget",
  props: /* @__PURE__ */ me({
    index: {
      type: Number,
      default: 0
    },
    hideExport: {
      type: Boolean,
      default: !1
    },
    customScreenWidth: {
      type: Number,
      required: !1,
      default: void 0
    }
  }, {
    modelValue: { required: !0, default: () => {
    } },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const n = h(!0), d = te(e, "modelValue"), t = d.value.widget.config, { t: x, te: C } = Me(), k = e, z = h(null), L = h(t.rollup), c = h($e()), u = h(t.drillDimension), r = y(() => {
      if (ce.value.length > 0) {
        const a = ce.value.findIndex(
          ($) => $.value === u.value
        );
        return a >= 0 ? a : 0;
      } else
        return -1;
    }), i = y(() => r.value !== 0), w = y(
      () => r.value != ce.value.length - 1
    ), p = h(t.showTitle ?? !0), f = h(t.titleFontSize ?? 14), g = h(t.titleBold ?? !1), E = h(t.titleItalic ?? !1), m = h(t.titleUnderline ?? !1), s = h(t.chartWidth ?? void 0), b = h(t.chartHeight ?? void 0), S = h(t.showLabel ?? !1), _ = h(t.labelAlign ?? Ze.center), A = h(t.labelAnchor ?? Ke.center), o = h(t.labelRotation ?? 0), v = h(t.labelOffset ?? 0), R = h(t.labelFontSize ?? 12), T = y(() => t.showSearchBar), D = h(t.showX ?? !0), H = h(t.xPosition ?? Qe.bottom), Y = h(t.showXGrid ?? !1), O = h(t.showXTick ?? !0), G = h(t.xTickFontSize ?? 12), j = h(t.showXTitle ?? !1), Ae = h(t.xTitle ?? ""), De = h(t.xTitleFontSize ?? 12), Ve = h(t.showY ?? !0), _e = h(t.yPosition ?? et.left), ke = h(t.showYGrid ?? !1), fe = h(t.showYTick ?? !0), se = h(t.yTickFontSize ?? 12), re = h(t.showYTitle ?? !1), ae = h(t.yTitle ?? ""), ve = h(t.yTitleFontSize ?? 12), le = h(t.showLegend ?? void 0), ie = h(t.legendPosition ?? tt.top), ue = h(t.usePointStyle ?? !0), Ne = h(t.legendMaxHeight ?? 54), ot = h(t.legendMaxWidth ?? 54), nt = h(t.rowHeight ?? 0), st = h(t.colWidths ?? []), Ie = h(!1), qe = h(""), { breakpoints: ge, getBreakpointsBoundary: Te } = ra(), rt = h(), I = y(
      () => k.customScreenWidth === void 0 ? window.innerWidth : k.customScreenWidth
    ), Ft = y(
      () => (I == null ? void 0 : I.value) > Te("xs")[1] && (I == null ? void 0 : I.value) <= Te("sm")[1]
    ), zt = y(
      () => (I == null ? void 0 : I.value) > Te("sm")[1] && (I == null ? void 0 : I.value) <= Te("md")[1]
    ), Lt = y(() => (I == null ? void 0 : I.value) > Te("md")[1]), Et = y(() => {
      const a = d.value.size.width;
      return Lt.value || zt.value ? La(a) : Ft.value ? Ea(a) : Wa(a);
    }), He = y(
      () => ia.find((a) => a.type === d.value.widget.type)
    ), ye = wt(() => {
      var a;
      rt.value = $t((a = z.value) == null ? void 0 : a.$el.offsetWidth), c.value = $e();
    }), Wt = y(() => {
      if (ua(M.value.type, be.value))
        switch (d.value.widget.type) {
          case F.BarChart:
            return da;
          case F.StackBarChart:
            return Fa;
          case F.LineChart:
            return Aa;
          case F.StackLineChart:
            return za;
          case F.Circular:
            return ha;
          case F.Scorecard:
            return ya;
          case F.Spacer:
            return xa;
          case F.Table:
            return Ra;
          default:
            return xt;
        }
      else
        return xt;
    }), be = h(null), {
      selectedLocationIds: Oe,
      dateRange: it,
      compareDateRange: At,
      timeRange: ut,
      globalFilters: Dt,
      isGlobalFiltersLoading: Ue
    } = Le(at()), { businessId: Vt } = Le(lt()), M = y(() => {
      const a = JSON.parse(JSON.stringify(d.value.widget));
      return {
        ...a,
        config: {
          ...a.config,
          rollup: L.value,
          drillDimension: u.value,
          showGrandTotal: !1
        }
      };
    });
    function Ht() {
      return {
        data: be.value,
        showTitle: p.value,
        titleFontSize: f.value,
        titleBold: g.value,
        titleItalic: E.value,
        titleUnderline: m.value,
        chartHeight: b.value,
        chartWidth: s.value,
        showLabel: S.value,
        labelAnchor: A.value,
        labelAlign: _.value,
        labelRotation: o.value,
        labelOffset: v.value,
        labelFontSize: R.value,
        showX: D.value,
        xPosition: H.value,
        showXGrid: Y.value,
        showXTick: O.value,
        xTickFontSize: G.value,
        showXTitle: j.value,
        xTitle: Ae.value,
        xTitleFontSize: De.value,
        showY: Ve.value,
        yPosition: _e.value,
        showYGrid: ke.value,
        showYTick: fe.value,
        yTitle: ae.value,
        showYTitle: re.value,
        yTitleFontSize: ve.value,
        yTickFontSize: se.value,
        isTransposed: M.value.config.isTransposed,
        showLegend: le.value,
        legendPosition: ie.value,
        usePointStyle: ue.value,
        legendMaxHeight: Ne.value,
        legendMaxWidth: ot.value
      };
    }
    function Bt() {
      return {
        data: be.value,
        filterText: qe.value,
        rollupPosition: M.value.config.rollupPosition,
        rowHeight: nt.value,
        colWidths: st.value
      };
    }
    const ct = y(() => {
      switch (M.value.type) {
        case F.Table:
          return Bt();
        case F.BarChart:
        case F.LineChart:
        case F.StackBarChart:
        case F.StackLineChart:
        case F.Circular:
          return Ht();
        default:
          return { data: be.value };
      }
    }), dt = y(() => {
      const { config: a } = d.value.widget;
      if (a.rollup != null) {
        const $ = [...a.dimensions].filter((de) => !de.hide);
        return $.sort(
          (de, Re) => (a.rowIds || []).indexOf(Ge(de)) - (a.rowIds || []).indexOf(Ge(Re))
        ), [
          { label: xe(x, C, "None", "other"), value: null },
          { label: xe(x, C, "Grand Total", "other"), value: 0 },
          ...[...$].slice(0, $.length - 1).map((de, Re) => ({
            label: xe(x, C, de.label, "other"),
            value: Re + 1
          }))
        ];
      }
      return [];
    }), ce = y(() => {
      const { config: a } = M.value;
      return a.isDrillable ? a.dimensions.map(($) => ({
        label: xe(x, C, $.label, "other"),
        value: Ge($)
      })) : [];
    });
    J(
      () => d.value.widget.config,
      (a) => {
        L.value = a.rollup, p.value = a.showTitle ?? !0, f.value = a.titleFontSize ?? 14, g.value = a.titleBold ?? !1, E.value = a.titleItalic ?? !1, m.value = a.titleUnderline ?? !1, b.value = a.chartHeight ?? void 0, s.value = a.chartWidth ?? void 0, S.value = a.showLabel ?? !1, _.value = a.labelAlign ?? Ze.center, A.value = a.labelAnchor ?? Ke.center, o.value = a.labelRotation ?? 0, v.value = a.labelOffset ?? 0, R.value = a.labelFontSize ?? 12, D.value = a.showX ?? !0, H.value = a.xPosition ?? Qe.bottom, Y.value = a.showXGrid ?? !1, O.value = a.showXTick ?? !0, G.value = a.xTickFontSize ?? 12, j.value = a.showXTitle ?? !1, Ae.value = a.xTitle ?? "", De.value = a.xTitleFontSize ?? 12, Ve.value = a.showY ?? !0, _e.value = a.yPosition ?? et.left, ke.value = a.showYGrid ?? !1, fe.value = a.showYTick ?? !0, se.value = a.yTickFontSize ?? 12, re.value = a.showYTitle ?? !1, ae.value = a.yTitle ?? "", ve.value = a.yTitleFontSize ?? 12, le.value = a.showLegend ?? void 0, ie.value = a.legendPosition ?? tt.top, ue.value = a.usePointStyle ?? !0, Ne.value = a.legendMaxHeight ?? 54, ot.value = a.legendMaxWidth ?? 54, nt.value = a.rowHeight ?? 0, st.value = a.colWidths ?? [];
      },
      { deep: !0 }
    ), J([() => L.value], () => {
      L.value !== null && (d.value.widget.config.rollup = L.value);
    }), J(
      [
        () => M.value,
        () => it.value,
        () => ut.value,
        () => At.value,
        () => Oe.value,
        () => Vt.value,
        () => Dt.value,
        () => Ue.value
      ],
      () => {
        mt();
      },
      {
        deep: !0
      }
    ), J(
      [() => d.value.size],
      () => {
        ye();
      },
      { deep: !0 }
    ), Se(() => {
      ye(), ge.value.sm || ge.value.md || ge.value.xs ? (console.log("Ignoring resize event due to keyboard"), addEventListener("change", ye)) : addEventListener("resize", ye), mt();
    }), Zt(() => {
      ge.value.sm || ge.value.md || ge.value.xs ? (console.log("Ignoring resize event due to keyboard"), removeEventListener("change", ye)) : removeEventListener("resize", ye);
    });
    const ht = Tt();
    let Be;
    async function mt() {
      if (Oe.value.length === 0 || Ue.value) {
        n.value = !1;
        return;
      }
      if (M.value.config.schemaNames.length <= 0 && !(M.value.config.dimensions.length <= 0 || M.value.config.metrics.length <= 0)) {
        ht.open({
          message: "schema must not be empty and dimension or metrics must have at least 1 column",
          type: "info"
        }), n.value = !1;
        return;
      }
      try {
        n.value = !0, Be && Be.abort(), Be = new AbortController();
        const a = Be.signal;
        be.value = await wt(aa, 500)(M.value, a, d.value.id), c.value = $e(), n.value = !1;
      } catch (a) {
        a.code !== "ERR_CANCELED" && (be.value = null, ht.open({ message: `Invalid chart ${M.value.type}`, type: "error" }), console.log(a), n.value = !1);
      }
    }
    function $t(a) {
      switch (d.value.widget.type) {
        case "SPACER":
          return;
        case "SCORECARD":
          return;
        case "TABLE":
          return `${d.value.size.height * 100 + (T.value ? 72 : 0) + 96.5}px`;
      }
      return `${Math.max(a / d.value.size.width, 90) * d.value.size.height}px`;
    }
    function Pt() {
      const a = r.value - 1;
      a >= 0 && (u.value = ce.value[a].value);
    }
    function Mt() {
      const a = r.value + 1;
      a >= 0 && a < ce.value.length && (u.value = ce.value[a].value);
    }
    const pt = h(Fe.EXCEL), ft = h(), Nt = Object.values(Fe).map((a) => ({
      label: la(a),
      value: a,
      onClick: async () => {
        a === Fe.EXCEL || a === Fe.PDFFULLSIZE ? await kt({
          reportType: a,
          index: k.index,
          timeRange: ut.value,
          dateRange: it.value,
          locationIds: Oe.value
        }) : a === Fe.PDF && (pt.value = a, ft.value = k.index, Ie.value = !0);
      }
    })), It = M.value.type === F.Spacer ? "flat" : "outlined", qt = M.value.type === F.Spacer ? "p-0" : "p-16";
    return (a, $) => {
      const de = V("FmTooltip"), Re = V("FmSearch"), Ot = V("FmCheckbox"), Xe = V("FmButton"), Ut = V("FmSelect"), Xt = V("FmMenuItem"), Yt = V("FmMenu"), Gt = V("FmForm"), jt = V("FmCircularProgress"), Jt = V("FmCard");
      return W(), U(Jt, {
        ref_key: "tileCard",
        ref: z,
        class: Pe(`${Et.value} ${l(qt)}`),
        variant: l(It)
      }, {
        default: q(() => [
          B(Ha, {
            modelValue: Ie.value,
            "onUpdate:modelValue": $[0] || ($[0] = (we) => Ie.value = we),
            "report-type": pt.value,
            index: ft.value
          }, null, 8, ["modelValue", "report-type", "index"]),
          !n.value && !l(Ue) ? (W(), N("div", {
            key: 0,
            style: ne({ height: rt.value })
          }, [
            (W(), U(Qt(Wt.value), {
              key: c.value,
              modelValue: ct.value,
              "onUpdate:modelValue": $[4] || ($[4] = (we) => ct.value = we),
              "tile-index": k.index
            }, {
              menu: q(() => [
                B(Gt, { class: "flex items-center gap-2" }, {
                  default: q(() => {
                    var we, vt, gt, yt;
                    return [
                      B(de, {
                        variant: "plain",
                        placement: "right",
                        content: M.value.description,
                        "hide-arrow": !0,
                        disabled: !M.value.description
                      }, {
                        default: q(() => [
                          p.value !== !1 ? (W(), N("p", {
                            key: 0,
                            style: ne({
                              fontSize: f.value + "px",
                              fontWeight: g.value ? "bold" : "normal",
                              fontStyle: E.value ? "italic" : "normal",
                              textDecoration: m.value ? "underline" : "none"
                            }),
                            class: Pe(["text-fm-color-typo-secondary line-clamp-1", [
                              f.value <= 18 ? "fm-typo-en-body-md-400" : "",
                              M.value.description ? "border-b-2 border-dashed border-gray-300" : ""
                            ]])
                          }, ze(l(xe)(l(x), l(C), M.value.title, "other")), 7)) : he("", !0)
                        ]),
                        _: 1
                      }, 8, ["content", "disabled"]),
                      (we = He.value) != null && we.showSearchBar ? (W(), U(Re, {
                        key: 0,
                        modelValue: qe.value,
                        "onUpdate:modelValue": $[1] || ($[1] = (K) => qe.value = K),
                        class: "grow"
                      }, null, 8, ["modelValue"])) : (W(), N("div", Ba)),
                      ea(B(Ot, {
                        modelValue: S.value,
                        "onUpdate:modelValue": $[2] || ($[2] = (K) => S.value = K),
                        label: "Label",
                        value: !1
                      }, null, 8, ["modelValue"]), [
                        [ta, (vt = He.value) == null ? void 0 : vt.showLabel]
                      ]),
                      (gt = He.value) != null && gt.showDrillDimension && ce.value.length > 0 ? (W(), N("div", $a, [
                        B(Xe, {
                          icon: "arrow_upward",
                          variant: "tertiary",
                          disabled: !i.value,
                          onClick: Pt
                        }, null, 8, ["disabled"]),
                        B(Xe, {
                          icon: "arrow_downward",
                          variant: "tertiary",
                          disabled: !w.value,
                          onClick: Mt
                        }, null, 8, ["disabled"])
                      ])) : he("", !0),
                      (yt = He.value) != null && yt.showRollup && dt.value.length > 0 ? (W(), U(Ut, {
                        key: 3,
                        modelValue: L.value,
                        "onUpdate:modelValue": $[3] || ($[3] = (K) => L.value = K),
                        class: "w-[150px]",
                        items: dt.value
                      }, null, 8, ["modelValue", "items"])) : he("", !0),
                      k.hideExport ? he("", !0) : (W(), U(Yt, {
                        key: 4,
                        shift: !0
                      }, {
                        "menu-button": q(() => [
                          B(Xe, {
                            icon: "more_vert",
                            variant: "tertiary"
                          })
                        ]),
                        default: q(() => [
                          (W(!0), N(oe, null, _t(l(Nt), (K) => (W(), U(Xt, {
                            key: K.value,
                            label: K.label,
                            onClick: K.onClick
                          }, null, 8, ["label", "onClick"]))), 128))
                        ]),
                        _: 1
                      }))
                    ];
                  }),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue", "tile-index"]))
          ], 4)) : (W(), U(jt, { key: 1 }))
        ]),
        _: 1
      }, 8, ["class", "variant"]);
    };
  }
});
export {
  Ze as L,
  Z as R,
  Ga as _,
  Ke as a,
  Ge as g,
  St as u
};
