import { computed as v, onMounted as _e, ref as u, watch as Te, openBlock as s, createElementBlock as n, normalizeClass as L, normalizeStyle as W, createBlock as x, createCommentVNode as d, unref as h, createSlots as Pe, withCtx as i, renderSlot as y, normalizeProps as I, guardReactiveProps as F, createVNode as oe, createElementVNode as $, Fragment as se, renderList as re, createTextVNode as ue, toDisplayString as O, nextTick as Se } from "vue";
import { u as Ne, o as Le, e as ne, g as Ie, c as ie, t as Fe, a as Oe, p as E, b as Ee, d as De, I as ce, L as Ve, f as k, X as Be, i as ve, x as de, y as Ge, q as Me, r as ze } from "./index-DK7qqHGP.js";
import { L as We } from "./Legend-D4PxDNTf.js";
import { _ as Ae } from "./Title-Cxlu3Etv.js";
import { _ as He } from "./Tooltip-Bt9pHzBM.js";
import { D as Ue } from "./DataTable-B9SSwFM2.js";
import { u as Xe, U as Re } from "./usePrinter-Cza87yNE.js";
import Ye from "./vue-ui-skeleton-CQnYuosp.js";
import je from "./vue-ui-accordion-5C4CP3gA.js";
import { u as he } from "./useNestedProp-0nRX_rTi.js";
import { _ as qe } from "./PackageVersion-I1_4jcn_.js";
import { _ as Je } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ke = ["id"], Qe = {
  key: 0,
  style: "width:100%;background:transparent;padding-bottom:24px"
}, Ze = ["xmlns", "viewBox"], et = ["id"], tt = ["stdDeviation"], lt = ["d", "stroke", "stroke-width"], at = ["d", "stroke", "stroke-width"], ot = ["filter"], st = ["d", "stroke", "stroke-width"], rt = ["d", "stroke-width", "onMouseenter", "onClick"], ut = {
  key: 3,
  class: "vue-data-ui-watermark"
}, nt = ["onClick"], it = { key: 0 }, ct = { key: 1 }, vt = ["innerHTML"], dt = {
  __name: "vue-ui-galaxy",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  emits: ["selectLegend", "selectDatapoint"],
  setup(ye, { expose: pe, emit: A }) {
    const p = ye, { vue_ui_galaxy: fe } = Ne(), S = v(() => !!p.dataset && p.dataset.length);
    _e(() => {
      H();
    });
    function H() {
      Le(p.dataset) ? ne({
        componentName: "VueUiGalaxy",
        type: "dataset"
      }) : p.dataset.forEach((t, a) => {
        Ie({
          datasetObject: t,
          requiredAttributes: ["name", "values"]
        }).forEach((l) => {
          ne({
            componentName: "VueUiGalaxy",
            type: "datasetSerieAttribute",
            property: l,
            index: a
          });
        });
      });
    }
    const _ = u(ie()), D = u(null), ge = u(null), V = u(!1), B = u(""), f = u(null), U = u(0), X = u(0), R = u(0), Y = u(0), e = v({
      get: () => j(),
      set: (t) => t
    });
    function j() {
      const t = he({
        userConfig: p.config,
        defaultConfig: fe
      });
      return t.theme ? {
        ...he({
          userConfig: Fe.vue_ui_galaxy[t.theme] || p.config,
          defaultConfig: t
        }),
        customPalette: Oe[t.theme] || E
      } : t;
    }
    Te(() => p.config, (t) => {
      e.value = j(), H(), X.value += 1, R.value += 1, Y.value += 1;
    }, { deep: !0 });
    const { isPrinting: q, isImaging: J, generatePdf: K, generateImage: Q } = Xe({
      elementId: `galaxy_${_.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-galaxy"
    }), be = v(() => Ee(e.value.customPalette)), b = u({
      dataLabels: {
        show: e.value.style.chart.layout.labels.dataLabels.show
      },
      showTable: e.value.table.show,
      showTooltip: e.value.style.chart.tooltip.show
    }), G = u({
      height: 180,
      // or 250 if non fibo
      width: 250
    }), c = u([]);
    function M(t) {
      c.value.includes(t.id) ? c.value = c.value.filter((a) => a !== t.id) : c.value.push(t.id), A("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: De(t.color) || be.value[a] || E[a] || E[a % E.length],
      value: t.values ? ce(t.values).reduce((l, o) => l + o, 0) : 0,
      absoluteValues: ce(t.values),
      id: ie(),
      seriesIndex: a
    })).sort((t, a) => a.value - t.value));
    function me() {
      return C.value.map((t) => ({
        name: t.name,
        color: t.color,
        value: t.value
      }));
    }
    const g = v(() => C.value.filter((t) => !c.value.includes(t.id)).map((t) => t.value).reduce((t, a) => t + a, 0)), ke = u(190), Z = v(() => C.value.filter((t) => !c.value.includes(t.id))), T = v(() => {
      const t = [];
      for (let a = 0; a < Z.value.length; a += 1) {
        const l = Z.value[a];
        let o = l.value / g.value * ke.value;
        a > 0 && t.length && (o += t[a - 1].points), t.push({
          points: o,
          ...l,
          seriesIndex: a,
          proportion: l.value / g.value,
          path: Ve({
            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);
    }), P = u(!1);
    function Ce(t) {
      P.value = t, U.value += 1;
    }
    const z = u(null);
    function we({ datapoint: t, _relativeIndex: a, seriesIndex: l, show: o = !1 }) {
      z.value = {
        datapoint: t,
        seriesIndex: l,
        series: C.value,
        config: e.value
      }, V.value = o, f.value = t.id;
      let r = "";
      const w = e.value.style.chart.tooltip.customFormat;
      de(w) && Ge(() => w({
        seriesIndex: l,
        datapoint: t,
        series: C.value,
        config: e.value
      })) ? B.value = w({
        seriesIndex: l,
        datapoint: t,
        series: C.value,
        config: e.value
      }) : (r += `<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>`, r += `<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 && (r += `<b>${ve(
        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 ? r += `<span>(${k({
        v: t.proportion * 100,
        s: "%",
        r: e.value.style.chart.tooltip.roundingPercentage
      })})</span></div>` : r += `<b>${k({
        v: t.proportion * 100,
        s: "%",
        r: e.value.style.chart.tooltip.roundingPercentage
      })}</b></div>`), B.value = `<div>${r}</div>`);
    }
    const ee = v(() => C.value.map((t, a) => ({
      ...t,
      proportion: (t.value || 0) / p.dataset.map((l) => (l.values || []).reduce((o, r) => o + r, 0)).reduce((l, o) => l + o, 0),
      opacity: c.value.includes(t.id) ? 0.5 : 1,
      shape: t.shape || "circle",
      segregate: () => M(t),
      isSegregated: c.value.includes(t.id)
    }))), xe = 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 te() {
      Se(() => {
        const t = m.value.head.map((o, r) => [[
          o.name
        ], [m.value.body[r]], [isNaN(m.value.body[r] / g.value) ? "-" : m.value.body[r] / g.value * 100]]), a = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[""], ["val"], ["%"]]].concat(t), l = Me(a);
        ze({ 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: g.value, s: e.value.style.chart.layout.labels.dataLabels.suffix, r: e.value.table.td.roundingValue }),
        "100%"
      ], a = m.value.head.map((r, w) => {
        const $e = 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: r.color,
            name: r.name
          },
          $e,
          isNaN(m.value.body[w] / g.value) ? "-" : k({
            v: m.value.body[w] / g.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 le() {
      b.value.showTable = !b.value.showTable;
    }
    function ae() {
      b.value.showTooltip = !b.value.showTooltip;
    }
    return pe({
      getData: me,
      generatePdf: K,
      generateCsv: te,
      generateImage: Q,
      toggleTable: le,
      toggleTooltip: ae
    }), (t, a) => (s(), n("div", {
      ref_key: "galaxyChart",
      ref: D,
      class: L(`vue-ui-galaxy ${P.value ? "vue-data-ui-wrapper-fullscreen" : ""} ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: W(`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 ? (s(), n("div", Qe, [
        (s(), x(Ae, {
          key: `title_${X.value}`,
          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"]))
      ])) : d("", !0),
      e.value.userOptions.show && S.value ? (s(), x(Re, {
        ref_key: "details",
        ref: ge,
        key: `user_option_${U.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: h(q),
        isImaging: h(J),
        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: P.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: D.value,
        position: e.value.userOptions.position,
        onToggleFullscreen: Ce,
        onGeneratePdf: h(K),
        onGenerateCsv: te,
        onGenerateImage: h(Q),
        onToggleTable: le,
        onToggleTooltip: ae
      }, Pe({ _: 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", I(F({ 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", "position", "onGeneratePdf", "onGenerateImage"])) : d("", !0),
      S.value ? (s(), n("svg", {
        key: 2,
        xmlns: h(Be),
        class: L({ "vue-data-ui-fullscreen--on": P.value, "vue-data-ui-fulscreen--off": !P.value }),
        viewBox: `0 0 ${G.value.width} ${G.value.height}`,
        style: W(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        oe(qe),
        $("defs", null, [
          $("filter", {
            id: `blur_${_.value}`,
            x: "-50%",
            y: "-50%",
            width: "200%",
            height: "200%"
          }, [
            $("feGaussianBlur", {
              in: "SourceGraphic",
              stdDeviation: 100 / e.value.style.chart.layout.arcs.gradient.intensity
            }, null, 8, tt)
          ], 8, et)
        ]),
        (s(!0), n(se, null, re(T.value, (l) => (s(), n("g", null, [
          l.value ? (s(), n("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) * (f.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, lt)) : d("", !0),
          l.value ? (s(), n("path", {
            key: 1,
            d: l.path,
            fill: "none",
            stroke: l.color,
            "stroke-width": e.value.style.chart.layout.arcs.strokeWidth * (f.value === l.id && e.value.style.chart.layout.arcs.hoverEffect.show ? e.value.style.chart.layout.arcs.hoverEffect.multiplicator : 1),
            "stroke-linecap": "round",
            class: L(`${f.value && f.value !== l.id && e.value.useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`)
          }, null, 10, at)) : d("", !0),
          l.value && e.value.style.chart.layout.arcs.gradient.show ? (s(), n("g", {
            key: 2,
            filter: `url(#blur_${_.value})`
          }, [
            $("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 * (f.value === l.id && e.value.style.chart.layout.arcs.hoverEffect.show ? e.value.style.chart.layout.arcs.hoverEffect.multiplicator : 1),
              "stroke-linecap": "round",
              class: L(`vue-ui-galaxy-gradient ${f.value && f.value !== l.id && e.value.useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`)
            }, null, 10, st)
          ], 8, ot)) : d("", !0)
        ]))), 256)),
        (s(!0), n(se, null, re(T.value, (l, o) => (s(), n("g", null, [
          l.value ? (s(), n("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: (r) => we({
              datapoint: l,
              relativeIndex: o,
              seriesIndex: l.seriesIndex,
              show: !0
            }),
            onMouseleave: a[0] || (a[0] = (r) => {
              V.value = !1, f.value = null;
            }),
            onClick: (r) => A("selectDatapoint", l)
          }, null, 40, rt)) : d("", !0)
        ]))), 256)),
        y(t.$slots, "svg", { svg: G.value }, void 0, !0)
      ], 14, Ze)) : d("", !0),
      t.$slots.watermark ? (s(), n("div", ut, [
        y(t.$slots, "watermark", I(F({ isPrinting: h(q) || h(J) })), void 0, !0)
      ])) : d("", !0),
      S.value ? d("", !0) : (s(), x(Ye, {
        key: 4,
        config: {
          type: "galaxy",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            galaxy: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      e.value.style.chart.legend.show ? (s(), x(We, {
        key: `legend_${Y.value}`,
        legendSet: ee.value,
        config: xe.value,
        onClickMarker: a[1] || (a[1] = ({ legend: l }) => M(l))
      }, {
        item: i(({ legend: l, index: o }) => [
          $("div", {
            onClick: (r) => M(l),
            style: W(`opacity:${c.value.includes(l.id) ? 0.5 : 1}`)
          }, [
            ue(O(l.name) + ": " + O(h(ve)(
              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) ? (s(), n("span", ct, " ( - % ) ")) : (s(), n("span", it, " (" + O(isNaN(l.value / g.value) ? "-" : h(k)({
              v: l.value / g.value * 100,
              s: "%",
              r: e.value.style.chart.legend.roundingPercentage
            })) + ") ", 1))
          ], 12, nt)
        ]),
        _: 1
      }, 8, ["legendSet", "config"])) : d("", !0),
      y(t.$slots, "legend", { legend: ee.value }, void 0, !0),
      oe(He, {
        show: b.value.showTooltip && V.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: D.value,
        content: B.value,
        isCustom: h(de)(e.value.style.chart.tooltip.customFormat)
      }, {
        "tooltip-before": i(() => [
          y(t.$slots, "tooltip-before", I(F({ ...z.value })), void 0, !0)
        ]),
        "tooltip-after": i(() => [
          y(t.$slots, "tooltip-after", I(F({ ...z.value })), void 0, !0)
        ]),
        _: 3
      }, 8, ["show", "backgroundColor", "color", "borderRadius", "borderColor", "borderWidth", "fontSize", "backgroundOpacity", "position", "offsetY", "parent", "content", "isCustom"]),
      S.value ? (s(), x(je, {
        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(() => [
          (s(), x(Ue, {
            key: `table_${R.value}`,
            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 }) => [
              $("div", {
                innerHTML: l,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, vt)
            ]),
            td: i(({ td: l }) => [
              ue(O(l.name || l), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"]))
        ]),
        _: 1
      }, 8, ["config"])) : d("", !0)
    ], 14, Ke));
  }
}, _t = /* @__PURE__ */ Je(dt, [["__scopeId", "data-v-20ef4a66"]]);
export {
  _t as default
};
