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