import { useCssVars as Ge, computed as f, ref as u, watch as Ve, onMounted as We, onBeforeUnmount as De, openBlock as i, createElementBlock as a, normalizeStyle as C, unref as r, createBlock as F, createCommentVNode as v, createSlots as Xe, withCtx as B, renderSlot as p, normalizeProps as A, guardReactiveProps as V, normalizeClass as W, createVNode as Ye, createElementVNode as qe, Fragment as P, renderList as L, mergeProps as ge, toDisplayString as T } 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 pe, g as tt, X as lt, G as ke, i as D, f as X, F as Y } from "./index-BbPeL8Gp.js";
import { t as st, u as it } from "./useResponsive-CoxXLe23.js";
import { _ as at } from "./Title-aSAft5dl.js";
import { u as nt, U as rt } from "./usePrinter-DaybDVqP.js";
import ut from "./vue-ui-skeleton-Bniq21d9.js";
import { u as xe } from "./useNestedProp-BN8claGG.js";
import { _ as ot } from "./PackageVersion-CxJghxYD.js";
import { P as ct } from "./PenAndPaper-ZdZEumki.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 = ["cx", "cy", "r", "stroke", "stroke-width"], gt = { key: 0 }, mt = ["stroke", "d", "stroke-width"], pt = { style: { "pointer-events": "none" } }, kt = ["cx", "cy", "fill", "r", "stroke"], xt = ["x", "y", "fill", "font-size"], wt = { key: 1 }, bt = ["stroke", "stroke-width", "x1", "x2", "y1", "y2"], $t = { style: { "pointer-events": "none" } }, _t = ["cx", "cy", "fill", "r", "stroke"], Ct = ["x", "y", "fill", "font-size"], Pt = ["text-anchor", "transform", "x", "y", "onClick", "font-weight", "font-size", "fill"], Lt = ["cx", "cy", "fill", "stroke", "onClick", "r"], Ot = {
  key: 5,
  class: "vue-data-ui-watermark"
}, zt = {
  __name: "vue-ui-relation-circle",
  props: {
    dataset: {
      type: Array,
      default() {
        return [];
      }
    },
    config: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(we, { expose: be }) {
    const k = we;
    Ge((e) => ({
      "530a5622": Oe.value,
      93815164: Le.value,
      "361f66b0": ze.value
    }));
    const { vue_ui_relation_circle: $e } = He(), E = f(() => !!k.dataset && Object.keys(k.dataset).length), O = u(Je()), q = u(0), z = u(null), H = u(null), J = u(null), K = u(null), Q = u(0), l = f({
      get: () => le(),
      set: (e) => e
    }), { userOptionsVisible: Z, setUserOptionsVisibility: ee, keepUserOptionState: te } = dt({ config: l.value });
    function le() {
      const e = xe({
        userConfig: k.config,
        defaultConfig: $e
      });
      return e.theme ? {
        ...xe({
          userConfig: Ke.vue_ui_relation_circle[e.theme] || k.config,
          defaultConfig: e
        }),
        customPalette: Qe[e.theme] || me
      } : e;
    }
    Ve(() => k.config, (e) => {
      l.value = le(), ce(), Q.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)), w = u([]), h = u([]), o = u({}), g = u([]), Ce = u(0), N = f(() => k.dataset.slice(0, l.value.style.limit)), $ = u(l.value.style.size), m = u(l.value.style.weightLabels.size), ue = u(l.value.style.plot.radius), oe = u(l.value.style.labels.fontSize), c = u({
      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 = u(null);
    We(() => {
      ce(), document.getElementById(`relation_circle_${O.value}`).addEventListener("click", de);
    });
    function ce() {
      if (et(k.dataset) ? pe({
        componentName: "VueUiRelationCircle",
        type: "dataset"
      }) : k.dataset.forEach((e, s) => {
        tt({
          datasetObject: e,
          requiredAttributes: ["id", "label", "relations", "weights"]
        }).forEach((t) => {
          pe({
            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 ? H.value : null,
            source: J.value,
            noTitle: K.value
          });
          $.value = Math.min(s, t), c.value.width = s, c.value.height = t, b.value = $.value * l.value.style.circle.radiusProportion, w.value = [], h.value = [], ve(), ye(), m.value = Y({
            relator: $.value,
            adjuster: l.value.style.size,
            source: l.value.style.weightLabels.size,
            threshold: 6,
            fallback: 6
          }), ue.value = Y({
            relator: $.value,
            adjuster: l.value.style.size,
            source: l.value.style.plot.radius,
            threshold: 1,
            fallback: 1
          }), oe.value = Y({
            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
        w.value = [], h.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") || (o.value = {}, g.value = []);
    }
    function ve() {
      const e = 6.28319 / N.value.length, s = 360 / N.value.length;
      let t = 0, n = 0;
      N.value.forEach((y, d) => {
        const U = y.weights.reduce((je, Ue) => je + Ue, 0), G = b.value * Math.cos(t) + c.value.width / 2, Re = b.value * Math.sin(t) + c.value.height / 2 + l.value.style.circle.offsetY;
        w.value.push({ x: G, y: Re, ...y, color: y.color ? y.color : re.value[d] ? re.value[d] : me[d], regAngle: n, totalWeight: U }), 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() {
      h.value = [], w.value.forEach((e) => {
        w.value.filter((t) => t.relations.includes(e.id)).forEach((t, n) => {
          const y = t.relations.indexOf(e.id);
          h.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: c.value.width / 2,
        y: c.value.height / 2 + l.value.style.circle.offsetY
      }, d = 0.5, U = 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, G = 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: U, y: G };
    }
    const Me = f(() => Math.max(...h.value.map((e) => e.weight)));
    function Se(e) {
      return Object.hasOwn(o.value, "x") ? g.value.includes(e.id) ? "opacity:1" : "opacity:0.1" : "opacity:1";
    }
    function x(e) {
      return e.colorSource;
    }
    function fe(e) {
      return Object.hasOwn(o.value, "x") ? g.value.includes(e.id) && e.relationId === `${e.id}_${o.value.id}` || e.relationId === `${o.value.id}_${e.id}` ? `opacity:1;stroke-width:${R(e)}` : "opacity: 0" : "opacity: 1";
    }
    function _(e) {
      return Object.hasOwn(o.value, "x") ? !!(g.value.includes(e.id) && e.relationId === `${e.id}_${o.value.id}` || e.relationId === `${o.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 Te(e) {
      return Object.hasOwn(o.value, "x") ? o.value.id === e.id || g.value.includes(e.id) ? "opacity:1" : "opacity:0.2" : "opacity:1";
    }
    function Ee(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, o.value.id && e.id === o.value.id ? (o.value = {}, g.value = []) : (o.value = e, g.value = [...e.relations]);
    }
    function R(e) {
      const s = e.weight / Me.value * l.value.style.links.maxWidth;
      return Math.max(0.3, s);
    }
    const M = u(!1);
    function Ne(e) {
      M.value = e, q.value += 1;
    }
    const S = u(!1);
    function j() {
      S.value = !S.value;
    }
    return be({
      generatePdf: ae,
      generateImage: ne,
      toggleAnnotator: j
    }), (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] = () => r(ee)(!0)),
      onMouseleave: s[1] || (s[1] = () => r(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: j
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : v("", !0),
      _e.value ? (i(), a("div", {
        key: 1,
        ref_key: "noTitle",
        ref: K,
        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: H,
        style: "width:100%;background:transparent"
      }, [
        (i(), F(at, {
          key: `title_${Q.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 && E.value && (r(te) || r(Z)) ? (i(), F(rt, {
        ref: "details",
        key: `user_options_${q.value}`,
        backgroundColor: l.value.style.backgroundColor,
        color: l.value.style.color,
        isPrinting: r(se),
        isImaging: r(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: r(ae),
        onGenerateImage: r(ne),
        onToggleAnnotator: j,
        style: C({
          visibility: r(te) ? r(Z) ? "visible" : "hidden" : "visible"
        })
      }, Xe({ _: 2 }, [
        e.$slots.optionPdf ? {
          name: "optionPdf",
          fn: B(() => [
            p(e.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        e.$slots.optionImg ? {
          name: "optionImg",
          fn: B(() => [
            p(e.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        e.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: B(({ toggleFullscreen: t, isFullscreen: n }) => [
            p(e.$slots, "optionFullscreen", A(V({ toggleFullscreen: t, isFullscreen: n })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        e.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: B(({ toggleAnnotator: t, isAnnotator: n }) => [
            p(e.$slots, "optionAnnotator", A(V({ 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),
      E.value ? (i(), a("svg", {
        key: 4,
        xmlns: r(lt),
        class: W([{ "vue-data-ui-fullscreen--on": M.value, "vue-data-ui-fulscreen--off": !M.value }, "relation-circle"]),
        viewBox: `0 0 ${c.value.width <= 0 ? 10 : c.value.width} ${c.value.height <= 0 ? 10 : c.value.height}`,
        width: "100%",
        style: "user-select:none; background:transparent"
      }, [
        Ye(ot),
        qe("circle", {
          cx: (c.value.width <= 0 ? 1e-4 : c.value.width) / 2,
          cy: (c.value.height <= 0 ? 1e-4 : c.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, ht),
        Pe.value ? (i(), a("g", gt, [
          (i(!0), a(P, null, L(h.value, (t, n) => (i(), a("path", {
            key: `relation_${n}`,
            style: C(fe(t)),
            stroke: x(t),
            class: W(["relation", { "vue-ui-relation-circle-selected": o.value.hasOwnProperty("id") && g.value.includes(t.id) }]),
            d: `M${t.x1},${t.y1} C${t.x1},${t.y1} ${c.value.width / 2},${c.value.height / 2 + l.value.style.circle.offsetY} ${t.x2},${t.y2}`,
            fill: "none",
            "stroke-width": R(t),
            "stroke-linecap": "round"
          }, null, 14, mt))), 128)),
          (i(!0), a(P, null, L(h.value, (t, n) => (i(), a("g", pt, [
            _(t) ? p(e.$slots, "dataLabel", A(ge({ key: 0 }, {
              x: t.midPointBezier.x,
              y: t.midPointBezier.y,
              color: x(t),
              weight: t.weight,
              fontSize: m.value
            })), void 0, !0) : v("", !0),
            _(t) && !e.$slots.dataLabel ? (i(), a("circle", {
              key: 1,
              cx: t.midPointBezier.x,
              cy: t.midPointBezier.y,
              fill: x(t),
              r: m.value,
              stroke: l.value.style.backgroundColor,
              "stroke-width": "1"
            }, null, 8, kt)) : v("", !0),
            _(t) && !e.$slots.dataLabel ? (i(), a("text", {
              key: 2,
              x: t.midPointBezier.x,
              y: t.midPointBezier.y + m.value / 3,
              fill: r(ke)(x(t)),
              "text-anchor": "middle",
              "font-size": m.value
            }, T(r(D)(
              l.value.style.weightLabels.formatter,
              t.weight,
              r(X)({
                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", wt, [
          (i(!0), a(P, null, L(h.value, (t, n) => (i(), a("line", {
            key: `relation_${n}`,
            stroke: x(t),
            "stroke-width": R(t),
            style: C(fe(t)),
            x1: t.x1,
            x2: t.x2,
            y1: t.y1,
            y2: t.y2,
            class: W({ "vue-ui-relation-circle-selected": o.value.hasOwnProperty("id") && g.value.includes(t.id) }),
            "stroke-linecap": "round"
          }, null, 14, bt))), 128)),
          (i(!0), a(P, null, L(h.value, (t, n) => (i(), a("g", $t, [
            _(t) ? p(e.$slots, "dataLabel", A(ge({ key: 0 }, {
              x: t.midPointLine.x,
              y: t.midPointLine.y,
              color: x(t),
              weight: t.weight,
              fontSize: m.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: x(t),
              r: m.value,
              stroke: l.value.style.backgroundColor,
              "stroke-width": "1"
            }, null, 8, _t)) : v("", !0),
            _(t) && !e.$slots.dataLabel && l.value.style.weightLabels.show ? (i(), a("text", {
              key: 2,
              x: t.midPointLine.x,
              y: t.midPointLine.y + m.value / 3,
              fill: r(ke)(x(t)),
              "text-anchor": "middle",
              "font-size": m.value
            }, T(r(D)(
              l.value.style.weightLabels.formatter,
              t.weight,
              r(X)({
                p: l.value.style.weightLabels.prefix,
                v: t.weight,
                s: l.value.style.weightLabels.suffix,
                r: l.value.style.weightLabels.rounding
              }),
              { ...t }
            )), 9, Ct)) : v("", !0)
          ]))), 256))
        ])),
        (i(!0), a(P, null, L(w.value, (t, n) => (i(), a("text", {
          key: `plot_text_${n}`,
          "text-anchor": Fe(t),
          transform: Ee(t),
          x: Be(t),
          y: t.y + 5,
          onClick: (y) => he(t),
          class: "vue-ui-relation-circle-legend",
          "transform-origin": "start",
          "font-weight": o.value.id === t.id ? "900" : "400",
          style: C(`font-family:${l.value.style.fontFamily};${Te(t)}`),
          "font-size": oe.value,
          fill: l.value.style.labels.color
        }, T(t.label) + " (" + T(r(D)(
          l.value.style.weightLabels.formatter,
          t.totalWeight,
          r(X)({
            p: l.value.style.weightLabels.prefix,
            v: t.totalWeight,
            s: l.value.style.weightLabels.suffix,
            r: l.value.style.weightLabels.rounding
          }),
          { ...t }
        )) + ") ", 13, Pt))), 128)),
        (i(!0), a(P, null, L(w.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, Lt))), 128)),
        p(e.$slots, "svg", { svg: c.value }, void 0, !0)
      ], 10, ft)) : v("", !0),
      e.$slots.watermark ? (i(), a("div", Ot, [
        p(e.$slots, "watermark", A(V({ isPrinting: r(se) || r(ie) })), void 0, !0)
      ])) : v("", !0),
      e.$slots.source ? (i(), a("div", {
        key: 6,
        ref_key: "source",
        ref: J,
        dir: "auto"
      }, [
        p(e.$slots, "source", {}, void 0, !0)
      ], 512)) : v("", !0),
      E.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));
  }
}, Ut = /* @__PURE__ */ vt(zt, [["__scopeId", "data-v-0954f883"]]);
export {
  Ut as default
};
