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