import { useCssVars as ve, ref as v, computed as h, watch as Q, onMounted as ce, openBlock as s, createElementBlock as i, normalizeClass as D, createElementVNode as c, normalizeStyle as r, toDisplayString as p, createCommentVNode as m, Fragment as T, renderList as M, createBlock as V, unref as d, createSlots as fe, withCtx as A, renderSlot as C, normalizeProps as pe, guardReactiveProps as me, nextTick as be } from "vue";
import { u as ge, c as he, t as ye, a as _e, p as $, b as ke, o as xe, e as Y, g as Ce, d as Ie, $ as Se, i as P, f as z, q as we, r as Ae } from "./index-CFiXy4nY.js";
import { u as Z } from "./useNestedProp-3d6JiXbm.js";
import $e from "./vue-ui-sparkline-RfiNbiSF.js";
import Pe from "./BaseIcon-B2vcsAEz.js";
import { u as ze, U as Fe } from "./usePrinter-DaGf53v6.js";
import { _ as Oe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ne = ["id"], We = { style: { "z-index": "1", "padding-right": "24px" } }, De = ["onClick"], Te = { style: { display: "flex", "flex-direction": "row", gap: "3px", "align-items": "center" } }, Me = ["data-cell"], Ve = {
  dir: "auto",
  style: { display: "flex", "flex-direction": "row", "align-items": "center", gap: "6px" }
}, Ee = ["data-cell", "onPointerenter"], Ge = ["data-cell"], Le = ["data-cell"], Be = ["data-cell"], Re = ["data-cell"], Ue = {
  key: 0,
  ref: "source",
  dir: "auto"
}, He = {
  __name: "vue-ui-table-sparkline",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(j, { expose: ee }) {
    const b = j;
    ve((t) => ({
      "588e7231": t.tdo
    }));
    const { vue_ui_table_sparkline: te } = ge(), F = v(he()), E = v(0), I = v(0), e = h({
      get: () => G(),
      set: (t) => t
    });
    function G() {
      const t = Z({
        userConfig: b.config,
        defaultConfig: te
      });
      return t.theme ? {
        ...Z({
          userConfig: ye.vue_ui_table_sparkline[t.theme] || b.config,
          defaultConfig: t
        }),
        customPalette: _e[t.theme] || $
      } : t;
    }
    Q(() => b.config, (t) => {
      e.value = G(), q(), I.value += 1;
    }, { deep: !0 }), Q(() => b.dataset, (t) => {
      x.value = y.value, I.value += 1;
    }, { deep: !0 });
    const { isPrinting: L, isImaging: B, generatePdf: R, generateImage: U } = ze({
      elementId: `table_${F.value}`,
      fileName: e.value.title.text || "vue-ui-table-sparkline"
    }), ae = h(() => ke(e.value.customPalette)), S = v(null), H = v(!1), le = h(() => e.value.responsiveBreakpoint);
    ce(() => {
      q();
    });
    function q() {
      xe(b.dataset) && Y({
        componentName: "VueUiTableSparkline",
        type: "dataset"
      });
      const t = new ResizeObserver((u) => {
        u.forEach((a) => {
          H.value = a.contentRect.width < le.value;
        });
      });
      S.value && t.observe(S.value);
    }
    const X = h(() => (b.dataset.forEach((t, u) => {
      Ce({
        datasetObject: t,
        requiredAttributes: ["name", "values"]
      }).forEach((a) => {
        Y({
          componentName: "VueUiTableSparkline",
          type: "datasetSerieAttribute",
          property: a,
          index: u
        });
      });
    }), b.dataset.map((t, u) => {
      const a = (t.values || []).map((n) => isNaN(n) ? 0 : n ?? 0), o = a.reduce((n, l) => n + l, 0);
      return {
        ...t,
        values: t.values || [],
        color: Ie(t.color) || ae.value[u] || $[u] || $[u % $.length],
        sum: o,
        average: o / a.length,
        median: Se(a),
        sparklineDataset: a.map((n, l) => ({
          period: e.value.colNames[l] || `col ${l}`,
          value: n || 0
        }))
      };
    })));
    function oe(t) {
      const a = (t[0].values || []).map(
        (n, l) => t.map((f) => f.values[l] || [])
      ).map(
        (n) => n.map((l, f) => [l, f]).sort((l, f) => f[0] - l[0]).map((l) => l[1])
      );
      return t.map((n, l) => ({
        ...n,
        values: n.values || [],
        orders: a[l]
      }));
    }
    const y = h(() => oe(X.value)), x = v(y.value), ne = h(() => Math.max(...x.value.map((t) => (t.values || []).length))), w = v(void 0), O = v(!1), N = v(void 0), W = v(-1);
    function ue() {
      O.value = !1, N.value = void 0, W.value = -1, x.value = y.value;
    }
    function se(t) {
      O.value = !0, N.value = t;
      const u = y.value.map((l) => l.values[t] || []), a = w.value === t ? 1 : -1;
      W.value = a, t === w.value ? w.value = void 0 : w.value = t;
      const n = u.map((l, f) => [f, l]).sort((l, f) => a * (f[1] - l[1])).map((l) => l[0]).map((l) => y.value[l]);
      x.value = n, I.value += 1;
    }
    const re = h(() => Math.max(...b.dataset.map((t) => (t.values || []).length))), k = h(() => {
      let t = e.value.colNames;
      if (!t.length)
        for (let a = 0; a < re.value; a += 1)
          t.push(`col ${a + 1}`);
      e.value.showTotal && (t = [...t, e.value.translations.total]);
      let u;
      return e.value.showAverage && e.value.showMedian ? u = [
        ...t,
        e.value.translations.average,
        e.value.translations.median
      ] : e.value.showAverage && !e.value.showMedian ? u = [...t, e.value.translations.average] : !e.value.showAverage && e.value.showMedian ? u = [...t, e.value.translations.median] : u = t, e.value.showSparklines ? [...u, e.value.translations.chart] : u;
    }), g = v(void 0), _ = v(void 0);
    function ie({ dataIndex: t, serieIndex: u }) {
      g.value = t, _.value = u;
    }
    const J = v(!1);
    function de(t) {
      J.value = t, E.value += 1;
    }
    function K() {
      be(() => {
        const t = [e.value.translations.serie].concat(k.value), u = X.value.map((n, l) => [
          [n.name],
          n.values,
          [n.sum],
          [n.average],
          [n.median]
        ]), a = [t].concat(u), o = we(a);
        Ae({
          csvContent: o,
          title: e.value.title.text || "vue-ui-table-sparkline"
        });
      });
    }
    return ee({
      generatePdf: R,
      generateImage: U,
      generateCsv: K,
      restoreOrder: ue
    }), (t, u) => (s(), i("div", {
      ref_key: "tableContainer",
      ref: S,
      class: D({ "vue-ui-responsive": H.value }),
      style: { overflow: "hidden" },
      id: `table_${F.value}`
    }, [
      c("div", {
        style: { overflow: "auto" },
        onPointerleave: u[0] || (u[0] = (a) => {
          _.value = void 0, g.value = void 0;
        })
      }, [
        c("table", {
          class: "vue-ui-data-table",
          style: r({ fontFamily: e.value.fontFamily, position: "relative" })
        }, [
          e.value.title.text ? (s(), i("caption", {
            key: 0,
            style: r({ backgroundColor: e.value.title.backgroundColor })
          }, [
            c("div", {
              style: r({
                fontSize: `${e.value.title.fontSize}px`,
                fontWeight: e.value.title.bold ? "bold" : "normal",
                color: e.value.title.color,
                textAlign: e.value.title.textAlign
              })
            }, p(e.value.title.text), 5),
            e.value.title.subtitle.text ? (s(), i("div", {
              key: 0,
              style: r({
                fontSize: `${e.value.title.subtitle.fontSize}px`,
                fontWeight: e.value.title.subtitle.bold ? "bold" : "normal",
                color: e.value.title.subtitle.color,
                textAlign: e.value.title.textAlign
              })
            }, p(e.value.title.subtitle.text), 5)) : m("", !0)
          ], 4)) : m("", !0),
          c("thead", We, [
            c("tr", {
              role: "row",
              class: "vue-ui-data-table__thead-row",
              style: r({
                backgroundColor: e.value.thead.backgroundColor,
                color: e.value.thead.color
              })
            }, [
              c("th", {
                role: "cell",
                style: r({
                  backgroundColor: e.value.thead.backgroundColor,
                  outline: e.value.thead.outline,
                  textAlign: e.value.thead.textAlign,
                  fontWeight: e.value.thead.bold ? "bold" : "normal"
                }),
                class: "sticky-col-first"
              }, p(e.value.translations.serie), 5),
              (s(!0), i(T, null, M(k.value, (a, o) => (s(), i("th", {
                role: "cell",
                style: r({
                  background: e.value.thead.backgroundColor,
                  outline: e.value.thead.outline,
                  textAlign: e.value.thead.textAlign,
                  fontWeight: e.value.thead.bold ? "bold" : "normal",
                  minWidth: o === k.value.length - 1 ? "150px" : "",
                  cursor: y.value[0].values[o] !== void 0 ? "pointer" : "default"
                }),
                onClick: () => se(o),
                class: D({ "sticky-col": o === k.value.length - 1 && e.value.showSparklines })
              }, [
                c("div", Te, [
                  c("span", null, p(a), 1),
                  O.value && o === N.value && y.value[0].values[o] !== void 0 ? (s(), V(Pe, {
                    key: 0,
                    size: 18,
                    name: W.value === 1 ? "sort" : "sortReverse",
                    stroke: e.value.thead.color
                  }, null, 8, ["name", "stroke"])) : m("", !0)
                ]),
                e.value.userOptions.show && o === k.value.length - 1 ? (s(), V(Fe, {
                  ref_for: !0,
                  ref: "details",
                  key: `user_option_${E.value}`,
                  backgroundColor: e.value.thead.backgroundColor,
                  color: e.value.thead.color,
                  isPrinting: d(L),
                  isImaging: d(B),
                  uid: F.value,
                  hasPdf: e.value.userOptions.buttons.pdf,
                  hasXls: e.value.userOptions.buttons.csv,
                  hasImg: e.value.userOptions.buttons.img,
                  hasFullscreen: e.value.userOptions.buttons.fullscreen,
                  isFullscreen: J.value,
                  titles: { ...e.value.userOptions.buttonTitles },
                  chartElement: S.value,
                  position: e.value.userOptions.position,
                  onToggleFullscreen: de,
                  onGeneratePdf: d(R),
                  onGenerateImage: d(U),
                  onGenerateCsv: K
                }, fe({ _: 2 }, [
                  t.$slots.optionPdf ? {
                    name: "optionPdf",
                    fn: A(() => [
                      C(t.$slots, "optionPdf", {}, void 0, !0)
                    ]),
                    key: "0"
                  } : void 0,
                  t.$slots.optionCsv ? {
                    name: "optionCsv",
                    fn: A(() => [
                      C(t.$slots, "optionCsv", {}, void 0, !0)
                    ]),
                    key: "1"
                  } : void 0,
                  t.$slots.optionImg ? {
                    name: "optionImg",
                    fn: A(() => [
                      C(t.$slots, "optionImg", {}, void 0, !0)
                    ]),
                    key: "2"
                  } : void 0,
                  t.$slots.optionFullscreen ? {
                    name: "optionFullscreen",
                    fn: A(({ toggleFullscreen: n, isFullscreen: l }) => [
                      C(t.$slots, "optionFullscreen", pe(me({ toggleFullscreen: n, isFullscreen: l })), void 0, !0)
                    ]),
                    key: "3"
                  } : void 0
                ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasXls", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "onGeneratePdf", "onGenerateImage"])) : m("", !0)
              ], 14, De))), 256))
            ], 4)
          ]),
          c("tbody", null, [
            (s(!0), i(T, null, M(x.value, (a, o) => (s(), i("tr", {
              role: "row",
              style: r({
                backgroundColor: e.value.tbody.backgroundColor,
                color: e.value.tbody.color
              }),
              class: D({ "vue-ui-data-table__tbody__row": !0, "vue-ui-data-table__tbody__row-even": o % 2 === 0, "vue-ui-data-table__tbody__row-odd": o % 2 !== 0 })
            }, [
              c("td", {
                role: "cell",
                style: r({
                  backgroundColor: e.value.tbody.backgroundColor,
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign
                }),
                "data-cell": e.value.translations.serie,
                class: "vue-ui-data-table__tbody__td sticky-col-first"
              }, [
                c("div", Ve, [
                  c("span", {
                    style: r({ color: a.color })
                  }, "⬤", 4),
                  c("span", null, p(a.name ?? "-"), 1)
                ])
              ], 12, Me),
              (s(!0), i(T, null, M(ne.value, (n, l) => (s(), i("td", {
                dir: "auto",
                role: "cell",
                style: r({
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign,
                  backgroundColor: g.value !== void 0 && _.value !== void 0 && l === g.value && _.value === o ? `${a.color}33` : "",
                  borderRadius: g.value !== void 0 && _.value !== void 0 && l === g.value && _.value === o ? "3px" : ""
                }),
                "data-cell": k.value[l],
                class: "vue-ui-data-table__tbody__td",
                onPointerenter: (f) => {
                  _.value = o, g.value = l;
                }
              }, p([null, void 0].includes(a.values[l]) ? "-" : d(P)(
                e.value.formatter,
                Number(a.values[l]),
                d(z)({
                  p: e.value.prefix,
                  v: Number(a.values[l]),
                  s: e.value.suffix,
                  r: e.value.roundingValues
                }),
                { datapoint: a, seriesIndex: o, datapointIndex: l }
              )), 45, Ee))), 256)),
              e.value.showTotal ? (s(), i("td", {
                key: 0,
                dir: "auto",
                role: "cell",
                style: r({
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign
                }),
                "data-cell": e.value.translations.total,
                class: "vue-ui-data-table__tbody__td"
              }, p(d(P)(
                e.value.formatter,
                a.sum,
                d(z)({
                  p: e.value.prefix,
                  v: a.sum,
                  s: e.value.suffix,
                  r: e.value.roundingTotal
                }),
                { datapoint: a.sum, seriesIndex: o }
              )), 13, Ge)) : m("", !0),
              e.value.showAverage ? (s(), i("td", {
                key: 1,
                dir: "auto",
                role: "cell",
                style: r({
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign
                }),
                "data-cell": e.value.translations.average,
                class: "vue-ui-data-table__tbody__td"
              }, p(d(P)(
                e.value.formatter,
                a.average,
                d(z)({
                  p: e.value.prefix,
                  v: a.average,
                  s: e.value.suffix,
                  r: e.value.roundingAverage
                }),
                { datapoint: a.average, seriesIndex: o }
              )), 13, Le)) : m("", !0),
              e.value.showMedian ? (s(), i("td", {
                key: 2,
                dir: "auto",
                role: "cell",
                style: r({
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign
                }),
                "data-cell": e.value.translations.median,
                class: "vue-ui-data-table__tbody__td"
              }, p(d(P)(
                e.value.formatter,
                a.median,
                d(z)({
                  p: e.value.prefix,
                  v: a.median,
                  s: e.value.suffix,
                  r: e.value.roundingMedian
                }),
                { datapoint: a.median, seriesIndex: o }
              )), 13, Be)) : m("", !0),
              e.value.showSparklines ? (s(), i("td", {
                key: 3,
                role: "cell",
                "data-cell": e.value.translations.chart,
                style: r({
                  outline: e.value.tbody.outline,
                  fontSize: `${e.value.tbody.fontSize}px`,
                  fontWeight: e.value.tbody.bold ? "bold" : "normal",
                  textAlign: e.value.tbody.textAlign
                }),
                class: "vue-ui-data-table__tbody__td sticky-col"
              }, [
                (s(), V($e, {
                  key: `sparkline_${o}_${I.value}`,
                  onHoverIndex: ({ index: n }) => ie({ dataIndex: n, serieIndex: o }),
                  dataset: a.sparklineDataset,
                  showInfo: !1,
                  selectedIndex: g.value,
                  config: {
                    type: e.value.sparkline.type,
                    style: {
                      backgroundColor: e.value.tbody.backgroundColor,
                      animation: {
                        show: e.value.sparkline.animation.show && !d(L) && !d(B),
                        animationFrames: e.value.sparkline.animation.animationFrames
                      },
                      line: {
                        color: a.color,
                        smooth: e.value.sparkline.smooth,
                        strokeWidth: e.value.sparkline.strokeWidth
                      },
                      bar: {
                        color: a.color
                      },
                      area: {
                        color: a.color,
                        opacity: e.value.sparkline.showArea ? 16 : 0,
                        useGradient: e.value.sparkline.useGradient
                      },
                      verticalIndicator: {
                        color: a.color
                      },
                      plot: {
                        radius: 9,
                        stroke: e.value.tbody.backgroundColor,
                        strokeWidth: 3
                      }
                    }
                  }
                }, null, 8, ["onHoverIndex", "dataset", "selectedIndex", "config"]))
              ], 12, Re)) : m("", !0)
            ], 6))), 256))
          ])
        ], 4)
      ], 32),
      t.$slots.source ? (s(), i("div", Ue, [
        C(t.$slots, "source", {}, void 0, !0)
      ], 512)) : m("", !0)
    ], 10, Ne));
  }
}, je = /* @__PURE__ */ Oe(He, [["__scopeId", "data-v-1516623f"]]);
export {
  je as default
};
