import { ref as r, computed as d, onMounted as Ne, onBeforeUnmount as Pe, openBlock as i, createElementBlock as m, normalizeClass as V, normalizeStyle as _, createVNode as X, createCommentVNode as N, createBlock as B, unref as n, createSlots as Le, withCtx as p, renderSlot as g, normalizeProps as D, guardReactiveProps as U, Fragment as ne, renderList as ie, createElementVNode as w, createTextVNode as ve, toDisplayString as W, nextTick as Fe } from "vue";
import { u as Ie, c as ce, t as Se, a as Oe, p as T, o as Me, e as j, g as ze, b as Ae, F as Re, d as de, f as x, X as Ve, v as Be, w as De, s as Y, i as he, x as Ue, y as We, q as Ee, r as Ge } from "./index-CguVaFlt.js";
import { t as He, u as Xe } from "./useResponsive-NZB-WLRF.js";
import { _ as je } from "./Title-DbTGPg4G.js";
import { u as Ye, U as qe } from "./usePrinter-ClsMRVJG.js";
import { _ as Je } from "./Tooltip-u79R5W5y.js";
import { D as Ke } from "./DataTable-BwHWRlRZ.js";
import { L as Qe } from "./Legend-CsVEDSh6.js";
import Ze from "./vue-ui-skeleton-ChHLL5Hw.js";
import et from "./vue-ui-accordion-w15FGKRN.js";
import { u as pe } from "./useNestedProp-BbEbJmgv.js";
import { _ as tt } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const lt = ["id"], at = ["xmlns", "viewBox"], ot = ["id"], st = ["stop-color"], ut = ["stop-color"], rt = ["stroke", "cx", "cy", "r", "fill"], nt = ["stroke", "stroke-width", "cx", "cy", "r", "fill"], it = ["cx", "cy", "r", "onMouseenter"], vt = {
  key: 3,
  class: "vue-data-ui-watermark"
}, ct = ["onClick"], dt = { key: 0 }, ht = { key: 1 }, pt = ["innerHTML"], gt = {
  __name: "vue-ui-rings",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  emits: ["selectLegend"],
  setup(ge, { expose: fe, emit: ye }) {
    const f = ge, { vue_ui_rings: me } = Ie(), P = r(!1), O = d(() => !!f.dataset && f.dataset.length), L = r(ce()), be = r(null), M = r(!1), E = r(""), $ = r(null), q = r(0), F = r(null), J = r(null), K = r(null), e = d(() => {
      const t = pe({
        userConfig: f.config,
        defaultConfig: me
      });
      return t.theme ? {
        ...pe({
          userConfig: Se.vue_ui_rings[t.theme] || f.config,
          defaultConfig: t
        }),
        customPalette: Oe[t.theme] || T
      } : t;
    }), z = r(null);
    Ne(() => {
      if (Me(f.dataset) ? j({
        componentName: "VueUiRings",
        type: "dataset"
      }) : f.dataset.forEach((t, a) => {
        t.values.length || j({
          componentName: "VueUiRings",
          type: "dataset"
        }), ze({
          datasetObject: t,
          requiredAttributes: ["name", "values"]
        }).forEach((l) => {
          j({
            componentName: "VueUiRings",
            type: "datasetSerieAttribute",
            property: l,
            index: a
          });
        });
      }), e.value.responsive) {
        const t = He(() => {
          const { width: a, height: l } = Xe({
            chart: F.value,
            title: e.value.style.chart.title.text ? J.value : null,
            legend: e.value.style.chart.legend.show ? K.value : null
          });
          u.value.width = a, u.value.height = l;
        });
        z.value = new ResizeObserver(t), z.value.observe(F.value.parentNode);
      }
      setTimeout(() => {
        P.value = !0;
      }, 600);
    }), Pe(() => {
      z.value && z.value.disconnect();
    });
    const { isPrinting: Q, isImaging: Z, generatePdf: ee, generateImage: te } = Ye({
      elementId: `rings_${L.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-rings"
    }), le = d(() => Ae(e.value.customPalette)), k = r({
      showTable: e.value.table.show,
      showTooltip: e.value.style.chart.tooltip.show
    }), u = r({
      height: 360,
      width: 360
    }), ke = d(() => Math.min(u.value.height, u.value.width)), v = r([]);
    function G(t) {
      v.value.includes(t) ? v.value = v.value.filter((a) => a !== t) : v.value.push(t), ye("selectLegend", c.value.map((a) => ({
        name: a.name,
        color: a.color,
        value: a.value
      })));
    }
    const Ce = d(() => Math.max(
      ...A.value.filter((t) => !v.value.includes(t.uid)).map(({ value: t }) => t)
    ));
    function ae(t) {
      return t / Ce.value;
    }
    const A = d(() => f.dataset.map(({ values: t, name: a, color: l = null }, o) => {
      const s = Re(t).reduce((b, S) => b + S, 0);
      return {
        name: a,
        color: l || de(l) || le.value[o] || T[o] || T[o % T.length],
        value: s,
        proportion: s / f.dataset.map((b) => (b.values || []).reduce((S, _e) => S + _e, 0)).reduce((b, S) => b + S, 0),
        uid: ce()
      };
    })), oe = d(() => A.value.map((t) => ({
      ...t,
      shape: "circle",
      opacity: v.value.includes(t.uid) ? 0.5 : 1,
      segregate: () => G(t.uid),
      isSegregated: v.value.includes(t.uid)
    })).toSorted((t, a) => a.value - t.value)), we = d(() => ({
      cy: "rings-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" : ""
    })), y = d(() => A.value.filter((t) => !v.value.includes(t.uid)).map(({ value: t }) => t).reduce((t, a) => t + a, 0)), c = d(() => A.value.filter((t) => !v.value.includes(t.uid)).map(({ name: t, value: a, color: l = null, uid: o }, s) => ({
      uid: o,
      name: t,
      color: l || de(l) || le.value[s] || T[s] || T[s % T.length],
      value: a,
      proportion: ae(a),
      percentage: a / y.value * 100,
      strokeWidth: e.value.style.chart.layout.rings.strokeWidth * ae(a)
    })).toSorted((t, a) => a.value - t.value));
    function $e() {
      return c.value.map(
        ({ name: t, color: a, value: l, absoluteValues: o, percentage: s }) => ({
          name: t,
          color: a,
          value: l,
          absoluteValues: o,
          percentage: s
        })
      );
    }
    const h = d(() => ke.value - e.value.style.chart.layout.rings.strokeWidth * 2), H = r(null);
    function Te(t, a) {
      if (v.value.length === f.dataset.length) return;
      H.value = {
        datapoint: a,
        seriesIndex: t,
        series: c.value,
        config: e.value
      }, $.value = t;
      const l = c.value[t], o = e.value.style.chart.tooltip.customFormat;
      if (Ue(o) && We(() => o({
        seriesIndex: t,
        datapoint: a,
        series: c.value,
        config: e.value
      })))
        E.value = o({
          seriesIndex: t,
          datapoint: a,
          series: c.value,
          config: e.value
        });
      else {
        let s = "";
        s += `<div style="width:100%;text-align:center;border-bottom:1px solid ${e.value.style.chart.tooltip.borderColor};padding-bottom:6px;margin-bottom:3px;">${l.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="${l.color}" /></svg>`, e.value.style.chart.tooltip.showValue && (s += `<b>${he(
          e.value.style.chart.layout.labels.dataLabels.formatter,
          l.value,
          x({
            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.tooltip.roundingValue
          }),
          { datapoint: a, seriesIndex: t }
        )}
      </b>`), e.value.style.chart.tooltip.showPercentage && (e.value.style.chart.tooltip.showValue ? s += `<span>(${x({
          v: l.value / y.value * 100,
          s: "%",
          r: e.value.style.chart.tooltip.roundingPercentage
        })})</span></div>` : s += `<b>${x({
          v: l.value / y.value * 100,
          s: "%",
          r: e.value.style.chart.tooltip.roundingPercentage
        })}</b></div>`), E.value = s;
      }
      M.value = !0;
    }
    const C = d(() => {
      const t = c.value.map((l) => ({
        name: l.name,
        color: l.color
      })), a = c.value.map((l) => l.value);
      return { head: t, body: a };
    }), R = d(() => {
      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>',
        x({ p: e.value.style.chart.layout.labels.dataLabels.prefix, v: y.value, s: e.value.style.chart.layout.labels.dataLabels.suffix, r: e.value.table.td.roundingValue }),
        "100%"
      ], a = C.value.head.map((s, b) => [
        {
          color: s.color,
          name: s.name
        },
        x({ p: e.value.style.chart.layout.labels.dataLabels.prefix, v: C.value.body[b], s: e.value.style.chart.layout.labels.dataLabels.suffix, r: e.value.table.td.roundingValue }),
        isNaN(C.value.body[b] / y.value) ? "-" : (C.value.body[b] / y.value * 100).toFixed(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
      }, o = [
        e.value.table.columnNames.series,
        e.value.table.columnNames.value,
        e.value.table.columnNames.percentage
      ];
      return {
        head: t,
        body: a,
        config: l,
        colNames: o
      };
    });
    function se() {
      Fe(() => {
        const t = C.value.head.map((o, s) => [[
          o.name
        ], [C.value.body[s]], [isNaN(C.value.body[s] / y.value) ? "-" : C.value.body[s] / y.value * 100]]), a = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[""], ["val"], ["%"]]].concat(t), l = Ee(a);
        Ge({ csvContent: l, title: e.value.style.chart.title.text || "vue-ui-rings" });
      });
    }
    const I = r(!1);
    function xe(t) {
      I.value = t, q.value += 1;
    }
    function ue() {
      k.value.showTable = !k.value.showTable;
    }
    function re() {
      k.value.showTooltip = !k.value.showTooltip;
    }
    return fe({
      getData: $e,
      generatePdf: ee,
      generateCsv: se,
      generateImage: te,
      toggleTable: ue,
      toggleTooltip: re
    }), (t, a) => (i(), m("div", {
      ref_key: "ringsChart",
      ref: F,
      class: V(`vue-ui-rings ${I.value ? "vue-data-ui-wrapper-fullscreen" : ""} ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: _(`font-family:${e.value.style.fontFamily};text-align:center;width:100%;background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height: 100%" : ""}`),
      id: `rings_${L.value}`,
      onMouseleave: a[3] || (a[3] = (l) => {
        $.value = null, M.value = !1;
      })
    }, [
      e.value.style.chart.title.text ? (i(), m("div", {
        key: 0,
        ref_key: "chartTitle",
        ref: J,
        style: _(`width:100%;background:${e.value.style.chart.backgroundColor}`)
      }, [
        X(je, {
          config: {
            title: {
              cy: "rings-div-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "rings-div-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"])
      ], 4)) : N("", !0),
      e.value.userOptions.show && O.value ? (i(), B(qe, {
        ref_key: "details",
        ref: be,
        key: `user_options_${q.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: n(Q),
        isImaging: n(Z),
        uid: L.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: k.value.showTooltip,
        isFullscreen: I.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: F.value,
        onToggleFullscreen: xe,
        onGeneratePdf: n(ee),
        onGenerateCsv: se,
        onGenerateImage: n(te),
        onToggleTable: ue,
        onToggleTooltip: re
      }, Le({ _: 2 }, [
        t.$slots.optionTooltip ? {
          name: "optionTooltip",
          fn: p(() => [
            g(t.$slots, "optionTooltip", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: p(() => [
            g(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionCsv ? {
          name: "optionCsv",
          fn: p(() => [
            g(t.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: p(() => [
            g(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionTable ? {
          name: "optionTable",
          fn: p(() => [
            g(t.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "4"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: p(({ toggleFullscreen: l, isFullscreen: o }) => [
            g(t.$slots, "optionFullscreen", D(U({ 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"])) : N("", !0),
      O.value ? (i(), m("svg", {
        key: 2,
        xmlns: n(Ve),
        class: V({ "vue-data-ui-fullscreen--on": I.value, "vue-data-ui-fulscreen--off": !I.value }),
        viewBox: `0 0 ${u.value.width <= 0 ? 10 : u.value.width} ${u.value.height <= 0 ? 10 : u.value.height}`,
        style: _(`max-width:100%;overflow:visible;background:${e.value.style.chart.backgroundColor};color:${e.value.style.chart.color}`)
      }, [
        (i(!0), m(ne, null, ie(c.value, (l, o) => (i(), m("radialGradient", {
          cx: "50%",
          cy: "30%",
          r: "50%",
          fx: "50%",
          fy: "50%",
          id: `gradient_${L.value}_${o}`
        }, [
          w("stop", {
            offset: "0%",
            "stop-color": `${n(Be)(l.color, 0.05)}${n(De)[100 - e.value.style.chart.layout.rings.gradient.intensity]}`
          }, null, 8, st),
          w("stop", {
            offset: "100%",
            "stop-color": l.color
          }, null, 8, ut)
        ], 8, ot))), 256)),
        (i(!0), m(ne, null, ie(c.value, (l, o) => (i(), m("g", null, [
          w("circle", {
            class: V({
              "vue-ui-rings-item": P.value && e.value.useCssAnimation,
              "vue-rings-item-onload": !P.value && e.value.useCssAnimation,
              "vue-ui-rings-opacity": $.value !== null && $.value !== o
            }),
            style: _(`animation-delay:${o * 100}ms`),
            stroke: e.value.style.chart.layout.rings.stroke,
            cx: u.value.width / 2,
            cy: o === 0 ? u.value.height / 2 : u.value.height / 2 + h.value * c.value[0].proportion / 2 - h.value * l.proportion / 2 - 2 * (o + 1),
            r: n(Y)(h.value * l.proportion / 2 * 0.9 <= 0 ? 1e-4 : h.value * l.proportion / 2 * 0.9),
            fill: e.value.style.chart.layout.rings.gradient.underlayerColor
          }, null, 14, rt),
          w("circle", {
            class: V({
              "vue-ui-rings-item": P.value && e.value.useCssAnimation,
              "vue-rings-item-onload": !P.value && e.value.useCssAnimation,
              "vue-ui-rings-shadow": e.value.style.chart.layout.rings.useShadow,
              "vue-ui-rings-blur": $.value !== null && $.value !== o
            }),
            style: _(`animation-delay:${o * 100}ms`),
            stroke: e.value.style.chart.layout.rings.stroke,
            "stroke-width": l.strokeWidth < 0.5 ? 0.5 : l.strokeWidth,
            cx: u.value.width / 2,
            cy: o === 0 ? u.value.height / 2 : u.value.height / 2 + h.value * c.value[0].proportion / 2 - h.value * l.proportion / 2 - 2 * (o + 1),
            r: n(Y)(h.value * l.proportion / 2 * 0.9 <= 0 ? 1e-4 : h.value * l.proportion / 2 * 0.9),
            fill: e.value.style.chart.layout.rings.gradient.show ? `url(#gradient_${L.value}_${o})` : l.color
          }, null, 14, nt),
          w("circle", {
            "data-cy-trap": "",
            stroke: "none",
            cx: u.value.width / 2,
            cy: o === 0 ? u.value.height / 2 : u.value.height / 2 + h.value * c.value[0].proportion / 2 - h.value * l.proportion / 2 - 2 * (o + 1),
            r: n(Y)(h.value * l.proportion / 2 * 0.9 <= 0 ? 1e-4 : h.value * l.proportion / 2 * 0.9),
            fill: "transparent",
            onMouseenter: (s) => Te(o, l),
            onMouseleave: a[0] || (a[0] = (s) => {
              $.value = null, M.value = !1;
            })
          }, null, 40, it)
        ]))), 256)),
        g(t.$slots, "svg", { svg: u.value }, void 0, !0)
      ], 14, at)) : N("", !0),
      t.$slots.watermark ? (i(), m("div", vt, [
        g(t.$slots, "watermark", D(U({ isPrinting: n(Q) || n(Z) })), void 0, !0)
      ])) : N("", !0),
      O.value ? N("", !0) : (i(), B(Ze, {
        key: 4,
        config: {
          type: "rings",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            rings: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      w("div", {
        ref_key: "chartLegend",
        ref: K
      }, [
        e.value.style.chart.legend.show ? (i(), B(Qe, {
          key: 0,
          legendSet: oe.value,
          config: we.value,
          onClickMarker: a[1] || (a[1] = ({ legend: l }) => G(l.uid))
        }, {
          item: p(({ legend: l, index: o }) => [
            w("div", {
              "data-cy-legend-item": "",
              onClick: (s) => G(l.uid),
              style: _(`opacity:${v.value.includes(l.uid) ? 0.5 : 1}`)
            }, [
              ve(W(l.name) + ": " + W(n(he)(
                e.value.style.chart.layout.labels.dataLabels.formatter,
                l.value,
                n(x)({
                  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),
              v.value.includes(l.uid) ? (i(), m("span", ht, " ( - % ) ")) : (i(), m("span", dt, " (" + W(isNaN(l.value / y.value) ? "-" : n(x)({
                v: l.value / y.value * 100,
                s: "%",
                r: e.value.style.chart.legend.roundingPercentage
              })) + ") ", 1))
            ], 12, ct)
          ]),
          _: 1
        }, 8, ["legendSet", "config"])) : g(t.$slots, "legend", {
          key: 1,
          legend: oe.value
        }, void 0, !0)
      ], 512),
      X(Je, {
        show: k.value.showTooltip && M.value && v.value.length < f.dataset.length,
        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: F.value,
        content: E.value,
        isCustom: e.value.style.chart.tooltip.customFormat && typeof e.value.style.chart.tooltip.customFormat == "function"
      }, {
        "tooltip-before": p(() => [
          g(t.$slots, "tooltip-before", D(U({ ...H.value })), void 0, !0)
        ]),
        "tooltip-after": p(() => [
          g(t.$slots, "tooltip-after", D(U({ ...H.value })), void 0, !0)
        ]),
        _: 3
      }, 8, ["show", "backgroundColor", "color", "borderRadius", "borderColor", "borderWidth", "fontSize", "backgroundOpacity", "position", "offsetY", "parent", "content", "isCustom"]),
      O.value ? (i(), B(et, {
        key: 5,
        hideDetails: "",
        config: {
          open: k.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: p(() => [
          X(Ke, {
            colNames: R.value.colNames,
            head: R.value.head,
            body: R.value.body,
            config: R.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) => k.value.showTable = !1)
          }, {
            th: p(({ th: l }) => [
              w("div", {
                innerHTML: l,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, pt)
            ]),
            td: p(({ td: l }) => [
              ve(W(l.name || l), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"])
        ]),
        _: 1
      }, 8, ["config"])) : N("", !0)
    ], 46, lt));
  }
}, Pt = /* @__PURE__ */ tt(gt, [["__scopeId", "data-v-30253e49"]]);
export {
  Pt as default
};
