import { useCssVars as J, ref as h, computed as c, onMounted as K, openBlock as n, createElementBlock as l, normalizeStyle as $, normalizeClass as T, createBlock as Q, unref as g, createSlots as Y, withCtx as C, renderSlot as r, normalizeProps as v, guardReactiveProps as f, createCommentVNode as p, createElementVNode as b, Fragment as _, renderList as w, createVNode as Z, mergeProps as V, nextTick as j } from "vue";
import { u as ee, c as z, t as te, o as ae, e as oe, U as se, E as ne, L as le, q as re, r as ue } from "./index-CguVaFlt.js";
import { u as M } from "./useNestedProp-BbEbJmgv.js";
import { u as ie, U as de } from "./usePrinter-ClsMRVJG.js";
import { _ as ce } from "./Shape-D3yIJobN.js";
import { _ as ve } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const pe = ["id"], me = { role: "cell" }, fe = { role: "row" }, he = ["data-cell"], ge = {
  key: 0,
  style: { display: "flex", "flex-direction": "row", gap: "2px", "align-items": "center" }
}, be = ["height", "width"], ye = {
  key: 0,
  role: "cell",
  "data-cell": "sum"
}, Ce = {
  key: 1,
  role: "cell",
  "data-cell": "average"
}, _e = {
  key: 2,
  role: "cell",
  "data-cell": "median"
}, ke = {
  __name: "vue-ui-table-heatmap",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(G, { expose: S }) {
    const m = G;
    J((e) => ({
      bb8dc4a0: W.value,
      "44bd448b": X.value
    }));
    const { vue_ui_table_heatmap: U } = ee(), k = h(z()), u = h(!1), y = h(null), I = h(!1), x = h(0), t = c(() => {
      const e = M({
        userConfig: m.config,
        defaultConfig: U
      });
      return e.theme ? {
        ...M({
          userConfig: te.vue_ui_table_heatmap[e.theme] || m.config,
          defaultConfig: e
        })
      } : e;
    }), { isPrinting: B, isImaging: A, generatePdf: F, generateImage: P } = ie({
      elementId: `table_heatmap_${k.value}`,
      fileName: "vue-ui-table-heatmap"
    }), D = c(() => t.value.table.responsiveBreakpoint), L = c(() => !!m.dataset && m.dataset.length);
    K(() => {
      ae(m.dataset) && oe({
        componentName: "VueUiTableHeatmap",
        type: "dataset"
      });
      const e = new ResizeObserver((s) => {
        s.forEach((a) => {
          u.value = a.contentRect.width < D.value;
        });
      });
      y.value && e.observe(y.value);
    });
    const N = c(() => m.dataset.map((e) => {
      const s = e.values.map((o) => isNaN(o) ? 0 : o), a = s.reduce((o, d) => o + d, 0);
      return {
        ...e,
        values: s,
        serieExtremes: {
          max: Math.max(...s),
          min: Math.min(...s)
        },
        sum: a,
        average: a / s.length,
        median: se(s),
        displayValues: [e.name, ...e.values],
        id: z()
      };
    })), O = c(() => {
      const e = N.value.flatMap((s) => s.values);
      return {
        min: Math.min(...e),
        max: Math.max(...e)
      };
    });
    function H(e, s) {
      const a = t.value.style.heatmapColors.useIndividualScale;
      return le(t.value.style.heatmapColors.min, t.value.style.heatmapColors.max, a ? s.min : O.value.min, a ? s.max : O.value.max, e);
    }
    const R = c(() => N.value.map((e) => ({
      ...e,
      colors: e.displayValues.map((s) => isNaN(s) ? t.value.style.backgroundColor : H(s, e.serieExtremes))
    }))), X = c(() => t.value.style.backgroundColor), W = c(() => `${t.value.table.borderWidth}px`);
    function E() {
      j(() => {
        const e = R.value.map((o) => [
          [o.name],
          o.displayValues,
          [o.sum],
          [o.average],
          [o.median]
        ]), s = [[[""], t.value.table.head.values, ["sum"], ["average"], ["median"]]].concat(e), a = re(s);
        ue({ csvContent: a, title: "vue-ui-table-heatmap" });
      });
    }
    function q(e) {
      I.value = e, x.value += 1;
    }
    return S({
      generatePdf: F,
      generateCsv: E,
      generateImage: P
    }), (e, s) => (n(), l("div", {
      ref_key: "tableContainer",
      ref: y,
      style: $(`width:100%; overflow-x:auto; container-type: inline-size;padding-top:${t.value.userOptions.show ? "36px" : ""}; ${I.value ? "vue-data-ui-wrapper-fullscreen" : ""}; position:relative;`),
      class: T({ "vue-ui-responsive": u.value }),
      id: `table_heatmap_${k.value}`
    }, [
      t.value.userOptions.show && L.value ? (n(), Q(de, {
        ref: "details",
        key: `user_option_${x.value}`,
        backgroundColor: t.value.style.backgroundColor,
        color: t.value.style.color,
        isPrinting: g(B),
        isImaging: g(A),
        uid: k.value,
        hasPdf: t.value.userOptions.buttons.pdf,
        hasXls: t.value.userOptions.buttons.csv,
        hasImg: t.value.userOptions.buttons.img,
        hasFullscreen: t.value.userOptions.buttons.fullscreen,
        isFullscreen: I.value,
        titles: { ...t.value.userOptions.buttonTitles },
        chartElement: y.value,
        onToggleFullscreen: q,
        onGeneratePdf: g(F),
        onGenerateCsv: E,
        onGenerateImage: g(P)
      }, Y({ _: 2 }, [
        e.$slots.optionPdf ? {
          name: "optionPdf",
          fn: C(() => [
            r(e.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        e.$slots.optionCsv ? {
          name: "optionCsv",
          fn: C(() => [
            r(e.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        e.$slots.optionImg ? {
          name: "optionImg",
          fn: C(() => [
            r(e.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        e.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: C(({ toggleFullscreen: a, isFullscreen: o }) => [
            r(e.$slots, "optionFullscreen", v(f({ toggleFullscreen: a, isFullscreen: o })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasXls", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "onGeneratePdf", "onGenerateImage"])) : p("", !0),
      b("table", {
        class: T({ "vue-ui-table-heatmap": !0 }),
        style: $(`width:100%;font-family:${t.value.style.fontFamily};background:${t.value.style.backgroundColor};`)
      }, [
        b("caption", null, [
          r(e.$slots, "caption", {}, void 0, !0)
        ]),
        b("thead", null, [
          b("tr", {
            role: "row",
            style: $(`background:${t.value.table.head.backgroundColor};color:${t.value.table.head.color}`)
          }, [
            (n(!0), l(_, null, w(t.value.table.head.values, (a, o) => (n(), l("th", me, [
              r(e.$slots, "head", v(f({ value: a, rowIndex: o, type: typeof a, isResponsive: u.value })), void 0, !0)
            ]))), 256))
          ], 4)
        ]),
        b("tbody", null, [
          (n(!0), l(_, null, w(R.value, (a, o) => (n(), l("tr", fe, [
            (n(!0), l(_, null, w(a.displayValues, (d, i) => (n(), l("td", {
              role: "cell",
              "data-cell": t.value.table.head.values[i]
            }, [
              a.color && i === 0 ? (n(), l("div", ge, [
                a.color ? (n(), l("svg", {
                  key: 0,
                  height: t.value.style.shapeSize,
                  width: t.value.style.shapeSize,
                  viewBox: "0 0 20 20",
                  style: { background: "none", overflow: "visible" }
                }, [
                  Z(ce, {
                    plot: { x: 10, y: 10 },
                    color: a.color,
                    radius: 9,
                    shape: a.shape || "circle"
                  }, null, 8, ["color", "shape"])
                ], 8, be)) : p("", !0),
                r(e.$slots, "rowTitle", v(f({ value: d, rowIndex: o, colIndex: i, type: typeof d, isResponsive: u.value })), void 0, !0)
              ])) : (n(), l(_, { key: 1 }, [
                i === 0 ? r(e.$slots, "rowTitle", v(V({ key: 0 }, { value: d, rowIndex: o, colIndex: i, type: typeof d, isResponsive: u.value })), void 0, !0) : p("", !0),
                i > 0 ? r(e.$slots, "cell", v(V({ key: 1 }, { value: d, rowIndex: o, colIndex: i, type: typeof d, isResponsive: u.value, color: a.colors[i], textColor: g(ne)(a.colors[i]) })), void 0, !0) : p("", !0)
              ], 64))
            ], 8, he))), 256)),
            t.value.table.showSum ? (n(), l("td", ye, [
              r(e.$slots, "sum", v(f({ value: a.sum, rowIndex: o, isResponsive: u.value })), void 0, !0)
            ])) : p("", !0),
            t.value.table.showAverage ? (n(), l("td", Ce, [
              r(e.$slots, "average", v(f({ value: a.average, rowIndex: o, isResponsive: u.value })), void 0, !0)
            ])) : p("", !0),
            t.value.table.showMedian ? (n(), l("td", _e, [
              r(e.$slots, "median", v(f({ value: a.median, rowIndex: o, isResponsive: u.value })), void 0, !0)
            ])) : p("", !0)
          ]))), 256))
        ])
      ], 4)
    ], 14, pe));
  }
}, Ne = /* @__PURE__ */ ve(ke, [["__scopeId", "data-v-3d431bc6"]]);
export {
  Ne as default
};
