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