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