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