import { useCssVars as Ge, computed as f, ref as o, watch as Ve, onMounted as We, onBeforeUnmount as De, openBlock as i, createElementBlock as a, normalizeStyle as C, unref as u, createBlock as F, createCommentVNode as v, createSlots as Xe, withCtx as B, renderSlot as h, normalizeProps as A, guardReactiveProps as W, normalizeClass as D, createVNode as Ye, createElementVNode as qe, Fragment as P, renderList as L, mergeProps as ge, toDisplayString as E } from "vue";
import { u as He, c as Je, t as Ke, a as Qe, p as me, b as Ze, o as et, e as ke, g as tt, X as lt, G as pe, i as X, f as Y, F as q } from "./index-BVNcFEqn.js";
import { t as st, u as it } from "./useResponsive-CoxXLe23.js";
import { _ as at } from "./Title-DyUTj8GI.js";
import { u as nt, U as rt } from "./usePrinter-Bcfs_I6G.js";
import ut from "./vue-ui-skeleton-Bgf16k10.js";
import { u as we } from "./useNestedProp-D79dWdel.js";
import { _ as ot } from "./PackageVersion-B9_Ed72C.js";
import { P as ct } from "./PenAndPaper-CzjoEhsO.js";
import { u as dt } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as vt } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const yt = ["id"], ft = ["xmlns", "viewBox"], ht = ["width", "height"], gt = ["cx", "cy", "r", "stroke", "stroke-width"], mt = { key: 1 }, kt = ["stroke", "d", "stroke-width"], pt = { style: { "pointer-events": "none" } }, wt = ["cx", "cy", "fill", "r", "stroke"], xt = ["x", "y", "fill", "font-size"], bt = { key: 2 }, $t = ["stroke", "stroke-width", "x1", "x2", "y1", "y2"], _t = { style: { "pointer-events": "none" } }, Ct = ["cx", "cy", "fill", "r", "stroke"], Pt = ["x", "y", "fill", "font-size"], Lt = ["text-anchor", "transform", "x", "y", "onClick", "font-weight", "font-size", "fill"], Ot = ["cx", "cy", "fill", "stroke", "onClick", "r"], zt = {
  key: 5,
  class: "vue-data-ui-watermark"
}, At = {
  __name: "vue-ui-relation-circle",
  props: {
    dataset: {
      type: Array,
      default() {
        return [];
      }
    },
    config: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(xe, { expose: be }) {
    const p = xe;
    Ge((e) => ({
      "4beec998": Oe.value,
      15467313: Le.value,
      e556a096: ze.value
    }));
    const { vue_ui_relation_circle: $e } = He(), T = f(() => !!p.dataset && Object.keys(p.dataset).length), O = o(Je()), H = o(0), z = o(null), J = o(null), K = o(null), Q = o(null), Z = o(0), l = f({
      get: () => le(),
      set: (e) => e
    }), { userOptionsVisible: N, setUserOptionsVisibility: ee, keepUserOptionState: te } = dt({ config: l.value });
    function le() {
      const e = we({
        userConfig: p.config,
        defaultConfig: $e
      });
      return e.theme ? {
        ...we({
          userConfig: Ke.vue_ui_relation_circle[e.theme] || p.config,
          defaultConfig: e
        }),
        customPalette: Qe[e.theme] || me
      } : e;
    }
    Ve(() => p.config, (e) => {
      l.value = le(), N.value = !l.value.showOnChartHover, ce(), Z.value += 1;
    }, { deep: !0 });
    const { isPrinting: se, isImaging: ie, generatePdf: ae, generateImage: ne } = nt({
      elementId: `relation_circle_${O.value}`,
      fileName: l.value.style.title.text || "vue-ui-relation-circle"
    }), _e = f(() => l.value.userOptions.show && !l.value.style.title.text), re = f(() => Ze(l.value.customPalette)), x = o([]), g = o([]), c = o({}), m = o([]), Ce = o(0), R = f(() => p.dataset.slice(0, l.value.style.limit)), $ = o(l.value.style.size), k = o(l.value.style.weightLabels.size), ue = o(l.value.style.plot.radius), oe = o(l.value.style.labels.fontSize), r = o({
      height: l.value.style.size,
      width: l.value.style.size
    }), b = f({
      get() {
        return $.value * l.value.style.circle.radiusProportion;
      },
      set(e) {
        return e;
      }
    }), Pe = f(() => l.value.style.links.curved), Le = f(() => `${l.value.style.animation.speedMs}ms`), Oe = f(() => b.value * 2), ze = f(() => b.value * 4), I = o(null);
    We(() => {
      ce(), document.getElementById(`relation_circle_${O.value}`).addEventListener("click", de);
    });
    function ce() {
      if (et(p.dataset) ? ke({
        componentName: "VueUiRelationCircle",
        type: "dataset"
      }) : p.dataset.forEach((e, s) => {
        tt({
          datasetObject: e,
          requiredAttributes: ["id", "label", "relations", "weights"]
        }).forEach((t) => {
          ke({
            componentName: "VueUiRelationCircle",
            type: "datasetSerieAttribute",
            property: t,
            index: s
          });
        });
      }), l.value.responsive) {
        const e = st(() => {
          const { width: s, height: t } = it({
            chart: z.value,
            title: l.value.style.title.text ? J.value : null,
            source: K.value,
            noTitle: Q.value
          });
          $.value = Math.min(s, t), r.value.width = s, r.value.height = t, b.value = $.value * l.value.style.circle.radiusProportion, x.value = [], g.value = [], ve(), ye(), k.value = q({
            relator: $.value,
            adjuster: l.value.style.size,
            source: l.value.style.weightLabels.size,
            threshold: 6,
            fallback: 6
          }), ue.value = q({
            relator: $.value,
            adjuster: l.value.style.size,
            source: l.value.style.plot.radius,
            threshold: 1,
            fallback: 1
          }), oe.value = q({
            relator: $.value,
            adjuster: l.value.style.size,
            source: l.value.style.labels.fontSize,
            threshold: 6,
            fallback: 6
          });
        });
        I.value = new ResizeObserver(e), I.value.observe(z.value.parentNode);
      } else
        x.value = [], g.value = [], ve(), ye();
    }
    De(() => {
      document.getElementById(`relation_circle_${O.value}`).removeEventListener("click", de), I.value && I.value.disconnect();
    });
    function de(e) {
      const s = e.target;
      s && Array.from(s.classList).includes("vue-ui-user-options") || s && Array.from(s.classList).includes("vue-ui-user-options-summary") || s && Array.from(s.classList).includes("vue-data-ui-button") || s && Array.from(s.classList).includes("vue-ui-relation-circle-legend") || (c.value = {}, m.value = []);
    }
    function ve() {
      const e = 6.28319 / R.value.length, s = 360 / R.value.length;
      let t = 0, n = 0;
      R.value.forEach((y, d) => {
        const G = y.weights.reduce((je, Ue) => je + Ue, 0), V = b.value * Math.cos(t) + r.value.width / 2, Re = b.value * Math.sin(t) + r.value.height / 2 + l.value.style.circle.offsetY;
        x.value.push({ x: V, y: Re, ...y, color: y.color ? y.color : re.value[d] ? re.value[d] : me[d], regAngle: n, totalWeight: G }), t += e, n += s;
      });
    }
    function Ae(e, s) {
      const t = (e.x + s.x) / 2, n = (e.y + s.y) / 2;
      return { x: t, y: n };
    }
    function ye() {
      g.value = [], x.value.forEach((e) => {
        x.value.filter((t) => t.relations.includes(e.id)).forEach((t, n) => {
          const y = t.relations.indexOf(e.id);
          g.value.push({
            weight: t.weights[y] ? t.weights[y] : 0,
            relationId: `${e.id}_${t.id}`,
            x1: e.x,
            y1: e.y,
            x2: t.x,
            y2: t.y,
            colorSource: e.color,
            colorTarget: t.color,
            midPointLine: Ae({ x: e.x, y: e.y }, { x: t.x, y: t.y }),
            midPointBezier: Ie({
              x1: e.x,
              x2: t.x,
              y1: e.y,
              y2: t.y
            }),
            ...e
          });
        });
      });
    }
    function Ie(e) {
      const s = { x: e.x1, y: e.y1 }, t = { x: e.x2, y: e.y2 }, n = { x: e.x1, y: e.y1 }, y = {
        x: r.value.width / 2,
        y: r.value.height / 2 + l.value.style.circle.offsetY
      }, d = 0.5, G = Math.pow(1 - d, 3) * s.x + 3 * Math.pow(1 - d, 2) * d * n.x + 3 * (1 - d) * Math.pow(d, 2) * y.x + Math.pow(d, 3) * t.x, V = Math.pow(1 - d, 3) * s.y + 3 * Math.pow(1 - d, 2) * d * n.y + 3 * (1 - d) * Math.pow(d, 2) * y.y + Math.pow(d, 3) * t.y;
      return { x: G, y: V };
    }
    const Me = f(() => Math.max(...g.value.map((e) => e.weight)));
    function Se(e) {
      return Object.hasOwn(c.value, "x") ? m.value.includes(e.id) ? "opacity:1" : "opacity:0.1" : "opacity:1";
    }
    function w(e) {
      return e.colorSource;
    }
    function fe(e) {
      return Object.hasOwn(c.value, "x") ? m.value.includes(e.id) && e.relationId === `${e.id}_${c.value.id}` || e.relationId === `${c.value.id}_${e.id}` ? `opacity:1;stroke-width:${j(e)}` : "opacity: 0" : "opacity: 1";
    }
    function _(e) {
      return Object.hasOwn(c.value, "x") ? !!(m.value.includes(e.id) && e.relationId === `${e.id}_${c.value.id}` || e.relationId === `${c.value.id}_${e.id}`) : !1;
    }
    function Fe(e) {
      return e.regAngle > 90 && e.regAngle < 270 ? "end" : "start";
    }
    function Be(e) {
      return e.regAngle > 90 && e.regAngle < 270 ? e.x - 5 : e.x + 5;
    }
    function Ee(e) {
      return Object.hasOwn(c.value, "x") ? c.value.id === e.id || m.value.includes(e.id) ? "opacity:1" : "opacity:0.2" : "opacity:1";
    }
    function Te(e) {
      return e.regAngle > 90 && e.regAngle < 270 ? `rotate(${e.regAngle + 180},${e.x},${e.y})` : `rotate(${e.regAngle},${e.x},${e.y})`;
    }
    function he(e) {
      Ce.value = 360 - e.regAngle, c.value.id && e.id === c.value.id ? (c.value = {}, m.value = []) : (c.value = e, m.value = [...e.relations]);
    }
    function j(e) {
      const s = e.weight / Me.value * l.value.style.links.maxWidth;
      return Math.max(0.3, s);
    }
    const M = o(!1);
    function Ne(e) {
      M.value = e, H.value += 1;
    }
    const S = o(!1);
    function U() {
      S.value = !S.value;
    }
    return be({
      generatePdf: ae,
      generateImage: ne,
      toggleAnnotator: U
    }), (e, s) => (i(), a("div", {
      ref_key: "relationCircleChart",
      ref: z,
      class: "vue-ui-relation-circle",
      style: C(`width:100%;background:${l.value.style.backgroundColor};text-align:center;${l.value.responsive ? "height: 100%" : ""}`),
      id: `relation_circle_${O.value}`,
      onMouseenter: s[0] || (s[0] = () => u(ee)(!0)),
      onMouseleave: s[1] || (s[1] = () => u(ee)(!1))
    }, [
      l.value.userOptions.buttons.annotator ? (i(), F(ct, {
        key: 0,
        parent: z.value,
        backgroundColor: l.value.style.backgroundColor,
        color: l.value.style.color,
        active: S.value,
        onClose: U
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : v("", !0),
      _e.value ? (i(), a("div", {
        key: 1,
        ref_key: "noTitle",
        ref: Q,
        class: "vue-data-ui-no-title-space",
        style: "height:36px; width: 100%;background:transparent"
      }, null, 512)) : v("", !0),
      l.value.style.title.text ? (i(), a("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: J,
        style: "width:100%;background:transparent"
      }, [
        (i(), F(at, {
          key: `title_${Z.value}`,
          config: {
            title: {
              cy: "relation-div-title",
              ...l.value.style.title
            },
            subtitle: {
              cy: "relation-div-subtitle",
              ...l.value.style.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 512)) : v("", !0),
      l.value.userOptions.show && T.value && (u(te) || u(N)) ? (i(), F(rt, {
        ref: "details",
        key: `user_options_${H.value}`,
        backgroundColor: l.value.style.backgroundColor,
        color: l.value.style.color,
        isPrinting: u(se),
        isImaging: u(ie),
        uid: O.value,
        hasPdf: l.value.userOptions.buttons.pdf,
        hasImg: l.value.userOptions.buttons.img,
        hasFullscreen: l.value.userOptions.buttons.img,
        hasXls: !1,
        isFullscreen: M.value,
        titles: { ...l.value.userOptions.buttonTitles },
        chartElement: z.value,
        position: l.value.userOptions.position,
        hasAnnotator: l.value.userOptions.buttons.annotator,
        isAnnotation: S.value,
        onToggleFullscreen: Ne,
        onGeneratePdf: u(ae),
        onGenerateImage: u(ne),
        onToggleAnnotator: U,
        style: C({
          visibility: u(te) ? u(N) ? "visible" : "hidden" : "visible"
        })
      }, Xe({ _: 2 }, [
        e.$slots.optionPdf ? {
          name: "optionPdf",
          fn: B(() => [
            h(e.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        e.$slots.optionImg ? {
          name: "optionImg",
          fn: B(() => [
            h(e.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        e.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: B(({ toggleFullscreen: t, isFullscreen: n }) => [
            h(e.$slots, "optionFullscreen", A(W({ toggleFullscreen: t, isFullscreen: n })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        e.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: B(({ toggleAnnotator: t, isAnnotator: n }) => [
            h(e.$slots, "optionAnnotator", A(W({ toggleAnnotator: t, isAnnotator: n })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : v("", !0),
      T.value ? (i(), a("svg", {
        key: 4,
        xmlns: u(lt),
        class: D([{ "vue-data-ui-fullscreen--on": M.value, "vue-data-ui-fulscreen--off": !M.value }, "relation-circle"]),
        viewBox: `0 0 ${r.value.width <= 0 ? 10 : r.value.width} ${r.value.height <= 0 ? 10 : r.value.height}`,
        width: "100%",
        style: "user-select:none; background:transparent"
      }, [
        Ye(ot),
        e.$slots["chart-background"] ? (i(), a("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: r.value.width <= 0 ? 10 : r.value.width,
          height: r.value.height <= 0 ? 10 : r.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          h(e.$slots, "chart-background", {}, void 0, !0)
        ], 8, ht)) : v("", !0),
        qe("circle", {
          cx: (r.value.width <= 0 ? 1e-4 : r.value.width) / 2,
          cy: (r.value.height <= 0 ? 1e-4 : r.value.height) / 2 + l.value.style.circle.offsetY,
          r: b.value <= 0 ? 1e-4 : b.value,
          stroke: l.value.style.circle.stroke,
          "stroke-width": l.value.style.circle.strokeWidth,
          fill: "transparent",
          class: "main-circle"
        }, null, 8, gt),
        Pe.value ? (i(), a("g", mt, [
          (i(!0), a(P, null, L(g.value, (t, n) => (i(), a("path", {
            key: `relation_${n}`,
            style: C(fe(t)),
            stroke: w(t),
            class: D(["relation", { "vue-ui-relation-circle-selected": c.value.hasOwnProperty("id") && m.value.includes(t.id) }]),
            d: `M${t.x1},${t.y1} C${t.x1},${t.y1} ${r.value.width / 2},${r.value.height / 2 + l.value.style.circle.offsetY} ${t.x2},${t.y2}`,
            fill: "none",
            "stroke-width": j(t),
            "stroke-linecap": "round"
          }, null, 14, kt))), 128)),
          (i(!0), a(P, null, L(g.value, (t, n) => (i(), a("g", pt, [
            _(t) ? h(e.$slots, "dataLabel", A(ge({ key: 0 }, {
              x: t.midPointBezier.x,
              y: t.midPointBezier.y,
              color: w(t),
              weight: t.weight,
              fontSize: k.value
            })), void 0, !0) : v("", !0),
            _(t) && !e.$slots.dataLabel ? (i(), a("circle", {
              key: 1,
              cx: t.midPointBezier.x,
              cy: t.midPointBezier.y,
              fill: w(t),
              r: k.value,
              stroke: l.value.style.backgroundColor,
              "stroke-width": "1"
            }, null, 8, wt)) : v("", !0),
            _(t) && !e.$slots.dataLabel ? (i(), a("text", {
              key: 2,
              x: t.midPointBezier.x,
              y: t.midPointBezier.y + k.value / 3,
              fill: u(pe)(w(t)),
              "text-anchor": "middle",
              "font-size": k.value
            }, E(u(X)(
              l.value.style.weightLabels.formatter,
              t.weight,
              u(Y)({
                p: l.value.style.weightLabels.prefix,
                v: t.weight,
                s: l.value.style.weightLabels.suffix,
                r: l.value.style.weightLabels.rounding
              }),
              { ...t }
            )), 9, xt)) : v("", !0)
          ]))), 256))
        ])) : (i(), a("g", bt, [
          (i(!0), a(P, null, L(g.value, (t, n) => (i(), a("line", {
            key: `relation_${n}`,
            stroke: w(t),
            "stroke-width": j(t),
            style: C(fe(t)),
            x1: t.x1,
            x2: t.x2,
            y1: t.y1,
            y2: t.y2,
            class: D({ "vue-ui-relation-circle-selected": c.value.hasOwnProperty("id") && m.value.includes(t.id) }),
            "stroke-linecap": "round"
          }, null, 14, $t))), 128)),
          (i(!0), a(P, null, L(g.value, (t, n) => (i(), a("g", _t, [
            _(t) ? h(e.$slots, "dataLabel", A(ge({ key: 0 }, {
              x: t.midPointLine.x,
              y: t.midPointLine.y,
              color: w(t),
              weight: t.weight,
              fontSize: k.value
            })), void 0, !0) : v("", !0),
            _(t) && !e.$slots.dataLabel && l.value.style.weightLabels.show ? (i(), a("circle", {
              key: 1,
              cx: t.midPointLine.x,
              cy: t.midPointLine.y,
              fill: w(t),
              r: k.value,
              stroke: l.value.style.backgroundColor,
              "stroke-width": "1"
            }, null, 8, Ct)) : v("", !0),
            _(t) && !e.$slots.dataLabel && l.value.style.weightLabels.show ? (i(), a("text", {
              key: 2,
              x: t.midPointLine.x,
              y: t.midPointLine.y + k.value / 3,
              fill: u(pe)(w(t)),
              "text-anchor": "middle",
              "font-size": k.value
            }, E(u(X)(
              l.value.style.weightLabels.formatter,
              t.weight,
              u(Y)({
                p: l.value.style.weightLabels.prefix,
                v: t.weight,
                s: l.value.style.weightLabels.suffix,
                r: l.value.style.weightLabels.rounding
              }),
              { ...t }
            )), 9, Pt)) : v("", !0)
          ]))), 256))
        ])),
        (i(!0), a(P, null, L(x.value, (t, n) => (i(), a("text", {
          key: `plot_text_${n}`,
          "text-anchor": Fe(t),
          transform: Te(t),
          x: Be(t),
          y: t.y + 5,
          onClick: (y) => he(t),
          class: "vue-ui-relation-circle-legend",
          "transform-origin": "start",
          "font-weight": c.value.id === t.id ? "900" : "400",
          style: C(`font-family:${l.value.style.fontFamily};${Ee(t)}`),
          "font-size": oe.value,
          fill: l.value.style.labels.color
        }, E(t.label) + " (" + E(u(X)(
          l.value.style.weightLabels.formatter,
          t.totalWeight,
          u(Y)({
            p: l.value.style.weightLabels.prefix,
            v: t.totalWeight,
            s: l.value.style.weightLabels.suffix,
            r: l.value.style.weightLabels.rounding
          }),
          { ...t }
        )) + ") ", 13, Lt))), 128)),
        (i(!0), a(P, null, L(x.value, (t, n) => (i(), a("circle", {
          cx: t.x,
          cy: t.y,
          key: `plot_${n}`,
          style: C(Se(t)),
          class: "vue-ui-relation-circle-plot",
          fill: l.value.style.plot.useSerieColor ? t.color : l.value.style.plot.color,
          stroke: l.value.style.backgroundColor,
          "stroke-width": "1",
          onClick: (y) => he(t),
          r: ue.value
        }, null, 12, Ot))), 128)),
        h(e.$slots, "svg", { svg: r.value }, void 0, !0)
      ], 10, ft)) : v("", !0),
      e.$slots.watermark ? (i(), a("div", zt, [
        h(e.$slots, "watermark", A(W({ isPrinting: u(se) || u(ie) })), void 0, !0)
      ])) : v("", !0),
      e.$slots.source ? (i(), a("div", {
        key: 6,
        ref_key: "source",
        ref: K,
        dir: "auto"
      }, [
        h(e.$slots, "source", {}, void 0, !0)
      ], 512)) : v("", !0),
      T.value ? v("", !0) : (i(), F(ut, {
        key: 7,
        config: {
          type: "relationCircle",
          style: {
            backgroundColor: l.value.style.backgroundColor,
            relationCircle: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 44, yt));
  }
}, Gt = /* @__PURE__ */ vt(At, [["__scopeId", "data-v-d95c92fd"]]);
export {
  Gt as default
};
