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