import { useCssVars as j, ref as g, computed as v, watch as ee, onMounted as te, openBlock as n, createElementBlock as l, normalizeStyle as C, normalizeClass as E, unref as u, createBlock as ae, createSlots as oe, withCtx as k, renderSlot as r, normalizeProps as c, guardReactiveProps as h, createCommentVNode as m, createElementVNode as b, Fragment as _, renderList as w, createVNode as se, mergeProps as G, nextTick as ne } from "vue";
import { u as le, c as B, t as re, o as ue, e as ie, $ as de, G as pe, N as ve, q as ce, r as me } from "./index-BbPeL8Gp.js";
import { u as A } from "./useNestedProp-BN8claGG.js";
import { u as fe, U as he } from "./usePrinter-DaybDVqP.js";
import { _ as ge } from "./Shape-DIKzzpFm.js";
import { u as be } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as ye } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ce = ["id"], ke = { role: "cell" }, _e = { role: "row" }, $e = ["data-cell"], Ie = {
  key: 0,
  style: { display: "flex", "flex-direction": "row", gap: "2px", "align-items": "center" }
}, we = ["height", "width"], xe = {
  key: 0,
  role: "cell",
  "data-cell": "sum"
}, Oe = {
  key: 1,
  role: "cell",
  "data-cell": "average"
}, Fe = {
  key: 2,
  role: "cell",
  "data-cell": "median"
}, Pe = {
  key: 1,
  ref: "source",
  dir: "auto"
}, Ne = {
  __name: "vue-ui-table-heatmap",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(D, { expose: H }) {
    const f = D;
    j((e) => ({
      "67270cdc": Y.value,
      "2c3bdf6d": Q.value
    }));
    const { vue_ui_table_heatmap: L } = le(), $ = g(B()), i = g(!1), y = g(null), I = g(!1), x = g(0), t = v({
      get: () => N(),
      set: (e) => e
    }), { userOptionsVisible: O, setUserOptionsVisibility: F, keepUserOptionState: P } = be({ config: t.value });
    function N() {
      const e = A({
        userConfig: f.config,
        defaultConfig: L
      });
      return e.theme ? {
        ...A({
          userConfig: re.vue_ui_table_heatmap[e.theme] || f.config,
          defaultConfig: e
        })
      } : e;
    }
    ee(() => f.config, (e) => {
      t.value = N(), M();
    }, { deep: !0 });
    const { isPrinting: X, isImaging: W, generatePdf: R, generateImage: V } = fe({
      elementId: `table_heatmap_${$.value}`,
      fileName: "vue-ui-table-heatmap"
    }), q = v(() => t.value.table.responsiveBreakpoint), J = v(() => !!f.dataset && f.dataset.length);
    te(() => {
      M();
    });
    function M() {
      ue(f.dataset) && ie({
        componentName: "VueUiTableHeatmap",
        type: "dataset"
      });
      const e = new ResizeObserver((o) => {
        o.forEach((a) => {
          i.value = a.contentRect.width < q.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: de(o),
        displayValues: [e.name, ...e.values],
        id: B()
      };
    })), T = v(() => {
      const e = S.value.flatMap((o) => o.values);
      return {
        min: Math.min(...e),
        max: Math.max(...e)
      };
    });
    function K(e, o) {
      const a = t.value.style.heatmapColors.useIndividualScale;
      return ve(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 : K(o, e.serieExtremes))
    }))), Q = v(() => t.value.style.backgroundColor), Y = v(() => `${t.value.table.borderWidth}px`);
    function z() {
      ne(() => {
        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 = ce(o);
        me({ csvContent: a, title: "vue-ui-table-heatmap" });
      });
    }
    function Z(e) {
      I.value = e, x.value += 1;
    }
    return H({
      generatePdf: R,
      generateCsv: z,
      generateImage: V
    }), (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" : ""}; ${I.value ? "vue-data-ui-wrapper-fullscreen" : ""}; position:relative;`),
      class: E({ "vue-ui-responsive": i.value }),
      id: `table_heatmap_${$.value}`,
      onMouseenter: o[0] || (o[0] = () => u(F)(!0)),
      onMouseleave: o[1] || (o[1] = () => u(F)(!1))
    }, [
      t.value.userOptions.show && J.value && (u(P) || u(O)) ? (n(), ae(he, {
        ref: "details",
        key: `user_option_${x.value}`,
        backgroundColor: t.value.style.backgroundColor,
        color: t.value.style.color,
        isPrinting: u(X),
        isImaging: u(W),
        uid: $.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,
        position: t.value.userOptions.position,
        onToggleFullscreen: Z,
        onGeneratePdf: u(R),
        onGenerateCsv: z,
        onGenerateImage: u(V),
        style: C({
          visibility: u(P) ? u(O) ? "visible" : "hidden" : "visible"
        })
      }, oe({ _: 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: E({ "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, w(t.value.table.head.values, (a, s) => (n(), l("th", ke, [
              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, w(U.value, (a, s) => (n(), l("tr", _e, [
            (n(!0), l(_, null, w(a.displayValues, (p, d) => (n(), l("td", {
              role: "cell",
              "data-cell": t.value.table.head.values[d]
            }, [
              a.color && d === 0 ? (n(), l("div", Ie, [
                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" }
                }, [
                  se(ge, {
                    plot: { x: 10, y: 10 },
                    color: a.color,
                    radius: 9,
                    shape: a.shape || "circle"
                  }, null, 8, ["color", "shape"])
                ], 8, we)) : 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(G({ 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(G({ key: 1 }, { value: p, rowIndex: s, colIndex: d, type: typeof p, isResponsive: i.value, color: a.colors[d], textColor: u(pe)(a.colors[d]) })), void 0, !0) : m("", !0)
              ], 64))
            ], 8, $e))), 256)),
            t.value.table.showSum ? (n(), l("td", xe, [
              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", Oe, [
              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", Fe, [
              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", Pe, [
        r(e.$slots, "source", {}, void 0, !0)
      ], 512)) : m("", !0)
    ], 46, Ce));
  }
}, Ee = /* @__PURE__ */ ye(Ne, [["__scopeId", "data-v-593bf1a5"]]);
export {
  Ee as default
};
