import { useCssVars as te, ref as g, useSlots as ae, onMounted as E, computed as v, watch as oe, openBlock as n, createElementBlock as l, normalizeStyle as C, normalizeClass as G, unref as u, createBlock as se, createSlots as ne, withCtx as k, renderSlot as r, normalizeProps as c, guardReactiveProps as h, createCommentVNode as m, createElementVNode as b, Fragment as _, renderList as x, createVNode as le, mergeProps as B, nextTick as re } from "vue";
import { u as ue, c as H, t as ie, o as de, e as pe, a0 as ve, G as ce, N as me, q as fe, r as he } from "./index-BVNcFEqn.js";
import { u as A } from "./useNestedProp-D79dWdel.js";
import { u as ge, U as be } from "./usePrinter-Bcfs_I6G.js";
import { _ as ye } from "./Shape-aXd72O71.js";
import { u as Ce } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as ke } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const _e = ["id"], Ie = { role: "cell" }, $e = { role: "row" }, we = ["data-cell"], xe = {
  key: 0,
  style: { display: "flex", "flex-direction": "row", gap: "2px", "align-items": "center" }
}, Oe = ["height", "width"], Fe = {
  key: 0,
  role: "cell",
  "data-cell": "sum"
}, Pe = {
  key: 1,
  role: "cell",
  "data-cell": "average"
}, Ne = {
  key: 2,
  role: "cell",
  "data-cell": "median"
}, Ve = {
  key: 1,
  ref: "source",
  dir: "auto"
}, Re = {
  __name: "vue-ui-table-heatmap",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(D, { expose: L }) {
    const f = D;
    te((e) => ({
      "51ba93f2": j.value,
      "63946c66": Z.value
    }));
    const { vue_ui_table_heatmap: X } = ue(), I = g(H()), i = g(!1), y = g(null), $ = g(!1), O = g(0), W = ae();
    E(() => {
      W["chart-background"] && console.warn("VueUiTableHeatmap does not support the #chart-background slot.");
    });
    const t = v({
      get: () => N(),
      set: (e) => e
    }), { userOptionsVisible: w, setUserOptionsVisibility: F, keepUserOptionState: P } = Ce({ config: t.value });
    function N() {
      const e = A({
        userConfig: f.config,
        defaultConfig: X
      });
      return e.theme ? {
        ...A({
          userConfig: ie.vue_ui_table_heatmap[e.theme] || f.config,
          defaultConfig: e
        })
      } : e;
    }
    oe(() => f.config, (e) => {
      t.value = N(), w.value = !t.value.showOnChartHover, M();
    }, { deep: !0 });
    const { isPrinting: q, isImaging: J, generatePdf: V, generateImage: R } = ge({
      elementId: `table_heatmap_${I.value}`,
      fileName: "vue-ui-table-heatmap"
    }), K = v(() => t.value.table.responsiveBreakpoint), Q = v(() => !!f.dataset && f.dataset.length);
    E(() => {
      M();
    });
    function M() {
      de(f.dataset) && pe({
        componentName: "VueUiTableHeatmap",
        type: "dataset"
      });
      const e = new ResizeObserver((o) => {
        o.forEach((a) => {
          i.value = a.contentRect.width < K.value;
        });
      });
      y.value && e.observe(y.value);
    }
    const S = v(() => f.dataset.map((e) => {
      const o = e.values.map((s) => isNaN(s) ? 0 : s), a = o.reduce((s, p) => s + p, 0);
      return {
        ...e,
        values: o,
        serieExtremes: {
          max: Math.max(...o),
          min: Math.min(...o)
        },
        sum: a,
        average: a / o.length,
        median: ve(o),
        displayValues: [e.name, ...e.values],
        id: H()
      };
    })), T = v(() => {
      const e = S.value.flatMap((o) => o.values);
      return {
        min: Math.min(...e),
        max: Math.max(...e)
      };
    });
    function Y(e, o) {
      const a = t.value.style.heatmapColors.useIndividualScale;
      return me(t.value.style.heatmapColors.min, t.value.style.heatmapColors.max, a ? o.min : T.value.min, a ? o.max : T.value.max, e);
    }
    const U = v(() => S.value.map((e) => ({
      ...e,
      colors: e.displayValues.map((o) => isNaN(o) ? t.value.style.backgroundColor : Y(o, e.serieExtremes))
    }))), Z = v(() => t.value.style.backgroundColor), j = v(() => `${t.value.table.borderWidth}px`);
    function z() {
      re(() => {
        const e = U.value.map((s) => [
          [s.name],
          s.displayValues,
          [s.sum],
          [s.average],
          [s.median]
        ]), o = [[[""], t.value.table.head.values, ["sum"], ["average"], ["median"]]].concat(e), a = fe(o);
        he({ csvContent: a, title: "vue-ui-table-heatmap" });
      });
    }
    function ee(e) {
      $.value = e, O.value += 1;
    }
    return L({
      generatePdf: V,
      generateCsv: z,
      generateImage: R
    }), (e, o) => (n(), l("div", {
      ref_key: "tableContainer",
      ref: y,
      style: C(`width:100%; overflow-x:auto; container-type: inline-size;padding-top:${t.value.userOptions.show ? "36px" : ""}; ${$.value ? "vue-data-ui-wrapper-fullscreen" : ""}; position:relative;`),
      class: G({ "vue-ui-responsive": i.value }),
      id: `table_heatmap_${I.value}`,
      onMouseenter: o[0] || (o[0] = () => u(F)(!0)),
      onMouseleave: o[1] || (o[1] = () => u(F)(!1))
    }, [
      t.value.userOptions.show && Q.value && (u(P) || u(w)) ? (n(), se(be, {
        ref: "details",
        key: `user_option_${O.value}`,
        backgroundColor: t.value.style.backgroundColor,
        color: t.value.style.color,
        isPrinting: u(q),
        isImaging: u(J),
        uid: I.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: $.value,
        titles: { ...t.value.userOptions.buttonTitles },
        chartElement: y.value,
        position: t.value.userOptions.position,
        onToggleFullscreen: ee,
        onGeneratePdf: u(V),
        onGenerateCsv: z,
        onGenerateImage: u(R),
        style: C({
          visibility: u(P) ? u(w) ? "visible" : "hidden" : "visible"
        })
      }, ne({ _: 2 }, [
        e.$slots.optionPdf ? {
          name: "optionPdf",
          fn: k(() => [
            r(e.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        e.$slots.optionCsv ? {
          name: "optionCsv",
          fn: k(() => [
            r(e.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        e.$slots.optionImg ? {
          name: "optionImg",
          fn: k(() => [
            r(e.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        e.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: k(({ toggleFullscreen: a, isFullscreen: s }) => [
            r(e.$slots, "optionFullscreen", c(h({ toggleFullscreen: a, isFullscreen: s })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasXls", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "onGeneratePdf", "onGenerateImage", "style"])) : m("", !0),
      b("table", {
        class: G({ "vue-ui-table-heatmap": !0 }),
        style: C(`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: C(`background:${t.value.table.head.backgroundColor};color:${t.value.table.head.color}`)
          }, [
            (n(!0), l(_, null, x(t.value.table.head.values, (a, s) => (n(), l("th", Ie, [
              r(e.$slots, "head", c(h({ value: a, rowIndex: s, type: typeof a, isResponsive: i.value })), void 0, !0)
            ]))), 256))
          ], 4)
        ]),
        b("tbody", null, [
          (n(!0), l(_, null, x(U.value, (a, s) => (n(), l("tr", $e, [
            (n(!0), l(_, null, x(a.displayValues, (p, d) => (n(), l("td", {
              role: "cell",
              "data-cell": t.value.table.head.values[d]
            }, [
              a.color && d === 0 ? (n(), l("div", xe, [
                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" }
                }, [
                  le(ye, {
                    plot: { x: 10, y: 10 },
                    color: a.color,
                    radius: 9,
                    shape: a.shape || "circle"
                  }, null, 8, ["color", "shape"])
                ], 8, Oe)) : m("", !0),
                r(e.$slots, "rowTitle", c(h({ value: p, rowIndex: s, colIndex: d, type: typeof p, isResponsive: i.value })), void 0, !0)
              ])) : (n(), l(_, { key: 1 }, [
                d === 0 ? r(e.$slots, "rowTitle", c(B({ key: 0 }, { value: p, rowIndex: s, colIndex: d, type: typeof p, isResponsive: i.value })), void 0, !0) : m("", !0),
                d > 0 ? r(e.$slots, "cell", c(B({ key: 1 }, { value: p, rowIndex: s, colIndex: d, type: typeof p, isResponsive: i.value, color: a.colors[d], textColor: u(ce)(a.colors[d]) })), void 0, !0) : m("", !0)
              ], 64))
            ], 8, we))), 256)),
            t.value.table.showSum ? (n(), l("td", Fe, [
              r(e.$slots, "sum", c(h({ value: a.sum, rowIndex: s, isResponsive: i.value })), void 0, !0)
            ])) : m("", !0),
            t.value.table.showAverage ? (n(), l("td", Pe, [
              r(e.$slots, "average", c(h({ value: a.average, rowIndex: s, isResponsive: i.value })), void 0, !0)
            ])) : m("", !0),
            t.value.table.showMedian ? (n(), l("td", Ne, [
              r(e.$slots, "median", c(h({ value: a.median, rowIndex: s, isResponsive: i.value })), void 0, !0)
            ])) : m("", !0)
          ]))), 256))
        ])
      ], 4),
      e.$slots.source ? (n(), l("div", Ve, [
        r(e.$slots, "source", {}, void 0, !0)
      ], 512)) : m("", !0)
    ], 46, _e));
  }
}, Be = /* @__PURE__ */ ke(Re, [["__scopeId", "data-v-4469b342"]]);
export {
  Be as default
};
