import { computed as v, onMounted as ke, ref as n, openBlock as r, createElementBlock as u, normalizeClass as S, normalizeStyle as L, createVNode as A, createCommentVNode as d, createBlock as I, unref as h, createSlots as Ce, withCtx as i, renderSlot as y, normalizeProps as F, guardReactiveProps as O, createElementVNode as x, Fragment as ee, renderList as te, createTextVNode as le, toDisplayString as E, nextTick as we } from "vue";
import { u as xe, o as $e, e as ae, g as Te, c as oe, t as _e, a as Pe, p as D, b as Ne, d as Se, F as se, I as Le, f as k, X as Ie, i as re, x as ue, y as Fe, q as Oe, r as Ee } from "./index-CguVaFlt.js";
import { L as De } from "./Legend-CsVEDSh6.js";
import { _ as Ve } from "./Title-DbTGPg4G.js";
import { _ as Be } from "./Tooltip-u79R5W5y.js";
import { D as Ge } from "./DataTable-BwHWRlRZ.js";
import { u as Me, U as ze } from "./usePrinter-ClsMRVJG.js";
import We from "./vue-ui-skeleton-ChHLL5Hw.js";
import Ae from "./vue-ui-accordion-w15FGKRN.js";
import { u as ne } from "./useNestedProp-BbEbJmgv.js";
import { _ as He } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ue = ["id"], Xe = ["xmlns", "viewBox"], Re = ["id"], Ye = ["stdDeviation"], je = ["d", "stroke", "stroke-width"], qe = ["d", "stroke", "stroke-width"], Je = ["filter"], Ke = ["d", "stroke", "stroke-width"], Qe = ["d", "stroke-width", "onMouseenter", "onClick"], Ze = {
  key: 3,
  class: "vue-data-ui-watermark"
}, et = ["onClick"], tt = { key: 0 }, lt = { key: 1 }, at = ["innerHTML"], ot = {
  __name: "vue-ui-galaxy",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  emits: ["selectLegend", "selectDatapoint"],
  setup(ie, { expose: ce, emit: H }) {
    const p = ie, { vue_ui_galaxy: ve } = xe(), P = v(() => !!p.dataset && p.dataset.length);
    ke(() => {
      $e(p.dataset) ? ae({
        componentName: "VueUiGalaxy",
        type: "dataset"
      }) : p.dataset.forEach((t, a) => {
        Te({
          datasetObject: t,
          requiredAttributes: ["name", "values"]
        }).forEach((l) => {
          ae({
            componentName: "VueUiGalaxy",
            type: "datasetSerieAttribute",
            property: l,
            index: a
          });
        });
      });
    });
    const $ = n(oe()), V = n(null), de = n(null), B = n(!1), G = n(""), g = n(null), U = n(0), e = v(() => {
      const t = ne({
        userConfig: p.config,
        defaultConfig: ve
      });
      return t.theme ? {
        ...ne({
          userConfig: _e.vue_ui_galaxy[t.theme] || p.config,
          defaultConfig: t
        }),
        customPalette: Pe[t.theme] || D
      } : t;
    }), { isPrinting: X, isImaging: R, generatePdf: Y, generateImage: j } = Me({
      elementId: `galaxy_${$.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-galaxy"
    }), he = v(() => Ne(e.value.customPalette)), b = n({
      dataLabels: {
        show: e.value.style.chart.layout.labels.dataLabels.show
      },
      showTable: e.value.table.show,
      showTooltip: e.value.style.chart.tooltip.show
    }), M = n({
      height: 180,
      // or 250 if non fibo
      width: 250
    }), c = n([]);
    function z(t) {
      c.value.includes(t.id) ? c.value = c.value.filter((a) => a !== t.id) : c.value.push(t.id), H("selectLegend", T.value.map((a) => ({
        name: a.name,
        color: a.color,
        value: a.value
      })));
    }
    const C = v(() => p.dataset.map((t, a) => ({
      name: t.name,
      color: Se(t.color) || he.value[a] || D[a] || D[a % D.length],
      value: t.values ? se(t.values).reduce((l, o) => l + o, 0) : 0,
      absoluteValues: se(t.values),
      id: oe(),
      seriesIndex: a
    })).sort((t, a) => a.value - t.value));
    function ye() {
      return C.value.map((t) => ({
        name: t.name,
        color: t.color,
        value: t.value
      }));
    }
    const f = v(() => C.value.filter((t) => !c.value.includes(t.id)).map((t) => t.value).reduce((t, a) => t + a, 0)), ge = n(190), q = v(() => C.value.filter((t) => !c.value.includes(t.id))), T = v(() => {
      const t = [];
      for (let a = 0; a < q.value.length; a += 1) {
        const l = q.value[a];
        let o = l.value / f.value * ge.value;
        a > 0 && t.length && (o += t[a - 1].points), t.push({
          points: o,
          ...l,
          seriesIndex: a,
          proportion: l.value / f.value,
          path: Le({
            points: o,
            startX: 115 + e.value.style.chart.layout.arcs.offsetX,
            startY: 90 + e.value.style.chart.layout.arcs.offsetY
          })
        });
      }
      return t.filter((a, l) => !c.value.includes(a.id)).toSorted((a, l) => l.points - a.points);
    }), _ = n(!1);
    function fe(t) {
      _.value = t, U.value += 1;
    }
    const W = n(null);
    function pe({ datapoint: t, _relativeIndex: a, seriesIndex: l, show: o = !1 }) {
      W.value = {
        datapoint: t,
        seriesIndex: l,
        series: C.value,
        config: e.value
      }, B.value = o, g.value = t.id;
      let s = "";
      const w = e.value.style.chart.tooltip.customFormat;
      ue(w) && Fe(() => w({
        seriesIndex: l,
        datapoint: t,
        series: C.value,
        config: e.value
      })) ? G.value = w({
        seriesIndex: l,
        datapoint: t,
        series: C.value,
        config: e.value
      }) : (s += `<div style="width:100%;text-align:center;border-bottom:1px solid ${e.value.style.chart.tooltip.borderColor};padding-bottom:6px;margin-bottom:3px;">${t.name}</div>`, s += `<div style="display:flex;flex-direction:row;gap:6px;align-items:center;"><svg viewBox="0 0 12 12" height="14" width="14"><circle cx="6" cy="6" r="6" stroke="none" fill="${t.color}"/></svg>`, e.value.style.chart.tooltip.showValue && (s += `<b>${re(
        e.value.style.chart.layout.labels.dataLabels.formatter,
        t.value,
        k({
          p: e.value.style.chart.layout.labels.dataLabels.prefix,
          v: t.value,
          s: e.value.style.chart.layout.labels.dataLabels.suffix,
          r: e.value.style.chart.tooltip.roundingValue
        }),
        { datapoint: t, seriesIndex: l }
      )}</b>`), e.value.style.chart.tooltip.showPercentage && (e.value.style.chart.tooltip.showValue ? s += `<span>(${k({
        v: t.proportion * 100,
        s: "%",
        r: e.value.style.chart.tooltip.roundingPercentage
      })})</span></div>` : s += `<b>${k({
        v: t.proportion * 100,
        s: "%",
        r: e.value.style.chart.tooltip.roundingPercentage
      })}</b></div>`), G.value = `<div>${s}</div>`);
    }
    const J = v(() => C.value.map((t, a) => ({
      ...t,
      proportion: (t.value || 0) / p.dataset.map((l) => (l.values || []).reduce((o, s) => o + s, 0)).reduce((l, o) => l + o, 0),
      opacity: c.value.includes(t.id) ? 0.5 : 1,
      shape: t.shape || "circle",
      segregate: () => z(t),
      isSegregated: c.value.includes(t.id)
    }))), be = v(() => ({
      cy: "galaxy-div-legend",
      backgroundColor: e.value.style.chart.legend.backgroundColor,
      color: e.value.style.chart.legend.color,
      fontSize: e.value.style.chart.legend.fontSize,
      paddingBottom: 12,
      fontWeight: e.value.style.chart.legend.bold ? "bold" : ""
    })), m = v(() => {
      const t = T.value.map((l) => ({
        name: l.name,
        color: l.color
      })), a = T.value.map((l) => l.value);
      return { head: t, body: a };
    });
    function K() {
      we(() => {
        const t = m.value.head.map((o, s) => [[
          o.name
        ], [m.value.body[s]], [isNaN(m.value.body[s] / f.value) ? "-" : m.value.body[s] / f.value * 100]]), a = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[""], ["val"], ["%"]]].concat(t), l = Oe(a);
        Ee({ csvContent: l, title: e.value.style.chart.title.text || "vue-ui-galaxy" });
      });
    }
    const N = v(() => {
      const t = [
        ' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>',
        k({ p: e.value.style.chart.layout.labels.dataLabels.prefix, v: f.value, s: e.value.style.chart.layout.labels.dataLabels.suffix, r: e.value.table.td.roundingValue }),
        "100%"
      ], a = m.value.head.map((s, w) => {
        const me = k({ p: e.value.style.chart.layout.labels.dataLabels.prefix, v: m.value.body[w], s: e.value.style.chart.layout.labels.dataLabels.suffix, r: e.value.table.td.roundingValue });
        return [
          {
            color: s.color,
            name: s.name
          },
          me,
          isNaN(m.value.body[w] / f.value) ? "-" : k({
            v: m.value.body[w] / f.value * 100,
            s: "%",
            r: e.value.table.td.roundingPercentage
          })
        ];
      }), l = {
        th: {
          backgroundColor: e.value.table.th.backgroundColor,
          color: e.value.table.th.color,
          outline: e.value.table.th.outline
        },
        td: {
          backgroundColor: e.value.table.td.backgroundColor,
          color: e.value.table.td.color,
          outline: e.value.table.td.outline
        },
        breakpoint: e.value.table.responsiveBreakpoint
      };
      return {
        colNames: [
          e.value.table.columnNames.series,
          e.value.table.columnNames.value,
          e.value.table.columnNames.percentage
        ],
        head: t,
        body: a,
        config: l
      };
    });
    function Q() {
      b.value.showTable = !b.value.showTable;
    }
    function Z() {
      b.value.showTooltip = !b.value.showTooltip;
    }
    return ce({
      getData: ye,
      generatePdf: Y,
      generateCsv: K,
      generateImage: j,
      toggleTable: Q,
      toggleTooltip: Z
    }), (t, a) => (r(), u("div", {
      ref_key: "galaxyChart",
      ref: V,
      class: S(`vue-ui-galaxy ${_.value ? "vue-data-ui-wrapper-fullscreen" : ""} ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: L(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;${e.value.style.chart.title.text ? "" : "padding-top:36px"};background:${e.value.style.chart.backgroundColor}`),
      id: `galaxy_${$.value}`
    }, [
      e.value.style.chart.title.text ? (r(), u("div", {
        key: 0,
        style: L(`width:100%;background:${e.value.style.chart.backgroundColor};padding-bottom:24px`)
      }, [
        A(Ve, {
          config: {
            title: {
              cy: "galaxy-div-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "galaxy-div-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"])
      ], 4)) : d("", !0),
      e.value.userOptions.show && P.value ? (r(), I(ze, {
        ref_key: "details",
        ref: de,
        key: `user_option_${U.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: h(X),
        isImaging: h(R),
        uid: $.value,
        hasTooltip: e.value.userOptions.buttons.tooltip && e.value.style.chart.tooltip.show,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasXls: e.value.userOptions.buttons.csv,
        hasImg: e.value.userOptions.buttons.img,
        hasTable: e.value.userOptions.buttons.table,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        isTooltip: b.value.showTooltip,
        isFullscreen: _.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: V.value,
        onToggleFullscreen: fe,
        onGeneratePdf: h(Y),
        onGenerateCsv: K,
        onGenerateImage: h(j),
        onToggleTable: Q,
        onToggleTooltip: Z
      }, Ce({ _: 2 }, [
        t.$slots.optionTooltip ? {
          name: "optionTooltip",
          fn: i(() => [
            y(t.$slots, "optionTooltip", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: i(() => [
            y(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionCsv ? {
          name: "optionCsv",
          fn: i(() => [
            y(t.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: i(() => [
            y(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionTable ? {
          name: "optionTable",
          fn: i(() => [
            y(t.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "4"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: i(({ toggleFullscreen: l, isFullscreen: o }) => [
            y(t.$slots, "optionFullscreen", F(O({ toggleFullscreen: l, isFullscreen: o })), void 0, !0)
          ]),
          key: "5"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasTooltip", "hasPdf", "hasXls", "hasImg", "hasTable", "hasFullscreen", "isTooltip", "isFullscreen", "titles", "chartElement", "onGeneratePdf", "onGenerateImage"])) : d("", !0),
      P.value ? (r(), u("svg", {
        key: 2,
        xmlns: h(Ie),
        class: S({ "vue-data-ui-fullscreen--on": _.value, "vue-data-ui-fulscreen--off": !_.value }),
        viewBox: `0 0 ${M.value.width} ${M.value.height}`,
        style: L(`max-width:100%; overflow: visible; background:${e.value.style.chart.backgroundColor};color:${e.value.style.chart.color}`)
      }, [
        x("defs", null, [
          x("filter", {
            id: `blur_${$.value}`,
            x: "-50%",
            y: "-50%",
            width: "200%",
            height: "200%"
          }, [
            x("feGaussianBlur", {
              in: "SourceGraphic",
              stdDeviation: 100 / e.value.style.chart.layout.arcs.gradient.intensity
            }, null, 8, Ye)
          ], 8, Re)
        ]),
        (r(!0), u(ee, null, te(T.value, (l) => (r(), u("g", null, [
          l.value ? (r(), u("path", {
            key: 0,
            d: l.path,
            fill: "none",
            stroke: e.value.style.chart.backgroundColor,
            "stroke-width": (e.value.style.chart.layout.arcs.strokeWidth + e.value.style.chart.layout.arcs.borderWidth) * (g.value === l.id && e.value.style.chart.layout.arcs.hoverEffect.show ? e.value.style.chart.layout.arcs.hoverEffect.multiplicator : 1),
            "stroke-linecap": "round"
          }, null, 8, je)) : d("", !0),
          l.value ? (r(), u("path", {
            key: 1,
            d: l.path,
            fill: "none",
            stroke: l.color,
            "stroke-width": e.value.style.chart.layout.arcs.strokeWidth * (g.value === l.id && e.value.style.chart.layout.arcs.hoverEffect.show ? e.value.style.chart.layout.arcs.hoverEffect.multiplicator : 1),
            "stroke-linecap": "round",
            class: S(`${g.value && g.value !== l.id && e.value.useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`)
          }, null, 10, qe)) : d("", !0),
          l.value && e.value.style.chart.layout.arcs.gradient.show ? (r(), u("g", {
            key: 2,
            filter: `url(#blur_${$.value})`
          }, [
            x("path", {
              d: l.path,
              fill: "none",
              stroke: e.value.style.chart.layout.arcs.gradient.color,
              "stroke-width": e.value.style.chart.layout.arcs.strokeWidth / 2 * (g.value === l.id && e.value.style.chart.layout.arcs.hoverEffect.show ? e.value.style.chart.layout.arcs.hoverEffect.multiplicator : 1),
              "stroke-linecap": "round",
              class: S(`vue-ui-galaxy-gradient ${g.value && g.value !== l.id && e.value.useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`)
            }, null, 10, Ke)
          ], 8, Je)) : d("", !0)
        ]))), 256)),
        (r(!0), u(ee, null, te(T.value, (l, o) => (r(), u("g", null, [
          l.value ? (r(), u("path", {
            key: 0,
            d: l.path,
            fill: "none",
            stroke: "transparent",
            "stroke-width": e.value.style.chart.layout.arcs.strokeWidth + e.value.style.chart.layout.arcs.borderWidth,
            "stroke-linecap": "round",
            onMouseenter: (s) => pe({
              datapoint: l,
              relativeIndex: o,
              seriesIndex: l.seriesIndex,
              show: !0
            }),
            onMouseleave: a[0] || (a[0] = (s) => {
              B.value = !1, g.value = null;
            }),
            onClick: (s) => H("selectDatapoint", l)
          }, null, 40, Qe)) : d("", !0)
        ]))), 256)),
        y(t.$slots, "svg", { svg: M.value }, void 0, !0)
      ], 14, Xe)) : d("", !0),
      t.$slots.watermark ? (r(), u("div", Ze, [
        y(t.$slots, "watermark", F(O({ isPrinting: h(X) || h(R) })), void 0, !0)
      ])) : d("", !0),
      P.value ? d("", !0) : (r(), I(We, {
        key: 4,
        config: {
          type: "galaxy",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            galaxy: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      e.value.style.chart.legend.show ? (r(), I(De, {
        key: 5,
        legendSet: J.value,
        config: be.value,
        onClickMarker: a[1] || (a[1] = ({ legend: l }) => z(l))
      }, {
        item: i(({ legend: l, index: o }) => [
          x("div", {
            onClick: (s) => z(l),
            style: L(`opacity:${c.value.includes(l.id) ? 0.5 : 1}`)
          }, [
            le(E(l.name) + ": " + E(h(re)(
              e.value.style.chart.layout.labels.dataLabels.formatter,
              l.value,
              h(k)({
                p: e.value.style.chart.layout.labels.dataLabels.prefix,
                v: l.value,
                s: e.value.style.chart.layout.labels.dataLabels.suffix,
                r: e.value.style.chart.legend.roundingValue
              }),
              { datapoint: l, seriesIndex: o }
            )) + " ", 1),
            c.value.includes(l.id) ? (r(), u("span", lt, " ( - % ) ")) : (r(), u("span", tt, " (" + E(isNaN(l.value / f.value) ? "-" : h(k)({
              v: l.value / f.value * 100,
              s: "%",
              r: e.value.style.chart.legend.roundingPercentage
            })) + ") ", 1))
          ], 12, et)
        ]),
        _: 1
      }, 8, ["legendSet", "config"])) : d("", !0),
      y(t.$slots, "legend", { legend: J.value }, void 0, !0),
      A(Be, {
        show: b.value.showTooltip && B.value,
        backgroundColor: e.value.style.chart.tooltip.backgroundColor,
        color: e.value.style.chart.tooltip.color,
        borderRadius: e.value.style.chart.tooltip.borderRadius,
        borderColor: e.value.style.chart.tooltip.borderColor,
        borderWidth: e.value.style.chart.tooltip.borderWidth,
        fontSize: e.value.style.chart.tooltip.fontSize,
        backgroundOpacity: e.value.style.chart.tooltip.backgroundOpacity,
        position: e.value.style.chart.tooltip.position,
        offsetY: e.value.style.chart.tooltip.offsetY,
        parent: V.value,
        content: G.value,
        isCustom: h(ue)(e.value.style.chart.tooltip.customFormat)
      }, {
        "tooltip-before": i(() => [
          y(t.$slots, "tooltip-before", F(O({ ...W.value })), void 0, !0)
        ]),
        "tooltip-after": i(() => [
          y(t.$slots, "tooltip-after", F(O({ ...W.value })), void 0, !0)
        ]),
        _: 3
      }, 8, ["show", "backgroundColor", "color", "borderRadius", "borderColor", "borderWidth", "fontSize", "backgroundOpacity", "position", "offsetY", "parent", "content", "isCustom"]),
      P.value ? (r(), I(Ae, {
        key: 6,
        hideDetails: "",
        config: {
          open: b.value.showTable,
          maxHeight: 1e4,
          body: {
            backgroundColor: e.value.style.chart.backgroundColor,
            color: e.value.style.chart.color
          },
          head: {
            backgroundColor: e.value.style.chart.backgroundColor,
            color: e.value.style.chart.color
          }
        }
      }, {
        content: i(() => [
          A(Ge, {
            colNames: N.value.colNames,
            head: N.value.head,
            body: N.value.body,
            config: N.value.config,
            title: `${e.value.style.chart.title.text}${e.value.style.chart.title.subtitle.text ? ` : ${e.value.style.chart.title.subtitle.text}` : ""}`,
            onClose: a[2] || (a[2] = (l) => b.value.showTable = !1)
          }, {
            th: i(({ th: l }) => [
              x("div", {
                innerHTML: l,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, at)
            ]),
            td: i(({ td: l }) => [
              le(E(l.name || l), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"])
        ]),
        _: 1
      }, 8, ["config"])) : d("", !0)
    ], 14, Ue));
  }
}, ft = /* @__PURE__ */ He(ot, [["__scopeId", "data-v-57d0334c"]]);
export {
  ft as default
};
