import { computed as y, ref as i, watch as V, onMounted as he, onBeforeUnmount as de, createElementBlock as c, openBlock as n, unref as s, normalizeStyle as A, createBlock as C, createCommentVNode as h, createSlots as ye, withCtx as _, renderSlot as f, normalizeProps as F, guardReactiveProps as S, normalizeClass as z, createVNode as fe, Fragment as J, renderList as K, toDisplayString as pe } from "vue";
import { u as ge, c as me, a as ke, o as we, e as be, w as Q, m as Ce, X as _e, i as Oe, v as Z, f as $e } from "./index-CjXfhpMA.js";
import { _ as xe } from "./Title-BfzkycPl.js";
import { u as Ie, U as Pe } from "./usePrinter-bLtFFBkj.js";
import { t as Ae, u as Fe } from "./useResponsive-BWapHhVH.js";
import Se from "./vue-ui-skeleton-B1q5j9VT.js";
import { u as ee } from "./useNestedProp-CmXi5M93.js";
import { _ as ze } from "./PackageVersion-ChIRiDpv.js";
import { P as Me } from "./PenAndPaper-OV0eQPcd.js";
import { u as Te } from "./useUserOptionState-BIvW1Kz7.js";
import { u as Ne } from "./useChartAccessibility-BWojgys7.js";
import { _ as Ue } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Re = ["id"], Xe = ["xmlns", "viewBox"], Le = ["width", "height"], Be = ["x1", "x2", "y1", "y2", "stroke", "stroke-width", "stroke-linecap"], Ee = ["d", "fill"], Ge = ["cx", "cy", "r", "stroke", "stroke-width"], je = ["x", "y", "font-size", "fill", "font-weight"], De = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Ye = {
  __name: "vue-ui-wheel",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(te, { expose: ae }) {
    const { vue_ui_wheel: le } = ge(), d = te, O = y(() => !!d.dataset && Object.keys(d.dataset).length), $ = i(me()), oe = i(null), M = i(0), p = i(null), T = i(null), N = i(null), U = i(null), R = i(0), e = y({
      get: () => B(),
      set: (t) => t
    }), { userOptionsVisible: x, setUserOptionsVisibility: X, keepUserOptionState: L } = Te({ config: e.value }), { svgRef: se } = Ne({ config: e.value.style.chart.title });
    function B() {
      const t = ee({
        userConfig: d.config,
        defaultConfig: le
      });
      return t.theme ? {
        ...ee({
          userConfig: ke.vue_ui_wheel[t.theme] || d.config,
          defaultConfig: t
        })
      } : t;
    }
    V(() => d.config, (t) => {
      e.value = B(), x.value = !e.value.userOptions.showOnChartHover, H(), R.value += 1;
    }, { deep: !0 });
    const { isPrinting: E, isImaging: G, generatePdf: j, generateImage: D } = Ie({
      elementId: $.value,
      fileName: e.value.style.chart.title.text || "vue-ui-wheel"
    }), ne = y(() => e.value.userOptions.show && !e.value.style.chart.title.text), l = i({
      size: 360,
      height: 360,
      width: 360
    }), I = i(e.value.style.chart.layout.percentage.fontSize), r = y(() => ({
      radius: Math.min(l.value.width, l.value.height) * 0.9 / 2,
      centerX: l.value.width / 2,
      centerY: l.value.height / 2
    }));
    function Y(t, o = 1) {
      return {
        x: r.value.centerX + r.value.radius * Math.cos(29.85 + t * Math.PI / 180) * o,
        y: r.value.centerY + r.value.radius * Math.sin(29.85 + t * Math.PI / 180) * o
      };
    }
    const u = i(e.value.style.chart.animation.use ? 0 : d.dataset.percentage || 0);
    V(() => d.dataset, (t) => {
      e.value.style.chart.animation.use ? W(t.percentage) : u.value = t.percentage || 0;
    }, { deep: !0 });
    const m = i(null);
    he(() => {
      H();
    });
    function H() {
      if (we(d.dataset) && be({
        componentName: "VueUiWheel",
        type: "dataset"
      }), W(d.dataset.percentage || 0), e.value.responsive) {
        const t = Ae(() => {
          const { width: o, height: a } = Fe({
            chart: p.value,
            title: e.value.style.chart.title.text ? T.value : null,
            source: N.value,
            noTitle: U.value
          });
          requestAnimationFrame(() => {
            l.value.width = o, l.value.height = a, I.value = e.value.style.chart.layout.percentage.fontSize / 360 * Math.min(o, a);
          });
        });
        m.value = new ResizeObserver(t), m.value.observe(p.value.parentNode);
      }
    }
    de(() => {
      m.value && m.value.disconnect();
    });
    function W(t) {
      let o = e.value.style.chart.animation.speed;
      const a = Math.abs(t - u.value) / (o * 120);
      function v() {
        u.value < t ? u.value = Math.min(u.value + a, t) : u.value > t && (u.value = Math.max(u.value - a, t)), u.value !== t && requestAnimationFrame(v);
      }
      v();
    }
    const g = y(() => Math.max(100, e.value.style.chart.layout.wheel.ticks.quantity)), k = y(() => 100 / g.value), q = y(() => {
      const t = [];
      for (let o = 0; o < g.value; o += 1) {
        const a = u.value > o * k.value ? e.value.style.chart.layout.wheel.ticks.activeColor : e.value.style.chart.layout.wheel.ticks.inactiveColor, { x: v, y: ie } = Y(l.value.size / g.value * o), { x: ce, y: ve } = Y(l.value.size / g.value * o, e.value.style.chart.layout.wheel.ticks.sizeRatio);
        t.push({
          x1: v,
          y1: ie,
          x2: ce,
          y2: ve,
          color: e.value.style.chart.layout.wheel.ticks.gradient.show ? Q(a, o * k.value / g.value * (e.value.style.chart.layout.wheel.ticks.gradient.shiftHueIntensity / 100)) : a
        });
      }
      return t;
    }), re = y(() => Ce({ series: q.value.map((t) => ({
      name: "",
      value: 1,
      color: t.color
    })) }, r.value.centerX, r.value.centerY, r.value.radius, r.value.radius, 1.99999, 2, 1, 360, 105.25, r.value.radius * (1 - e.value.style.chart.layout.wheel.ticks.sizeRatio))), w = i(!1);
    function ue(t) {
      w.value = t, M.value += 1;
    }
    const b = i(!1);
    function P() {
      b.value = !b.value;
    }
    return ae({
      generatePdf: j,
      generateImage: D,
      toggleAnnotator: P
    }), (t, o) => (n(), c("div", {
      class: "vue-ui-wheel",
      ref_key: "wheelChart",
      ref: p,
      id: $.value,
      style: A(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height:100%" : ""}`),
      onMouseenter: o[0] || (o[0] = () => s(X)(!0)),
      onMouseleave: o[1] || (o[1] = () => s(X)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (n(), C(Me, {
        key: 0,
        parent: p.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: b.value,
        onClose: P
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : h("", !0),
      ne.value ? (n(), c("div", {
        key: 1,
        ref_key: "noTitle",
        ref: U,
        class: "vue-data-ui-no-title-space",
        style: "height:36px; width: 100%;background:transparent"
      }, null, 512)) : h("", !0),
      e.value.style.chart.title.text ? (n(), c("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: T,
        style: "width:100%;background:transparent;padding-bottom:12px"
      }, [
        (n(), C(xe, {
          key: `title_${R.value}`,
          config: {
            title: {
              cy: "wheel-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "wheel-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 512)) : h("", !0),
      e.value.userOptions.show && O.value && (s(L) || s(x)) ? (n(), C(Pe, {
        ref_key: "details",
        ref: oe,
        key: `user_options_${M.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: s(E),
        isImaging: s(G),
        uid: $.value,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasImg: e.value.userOptions.buttons.img,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        hasXls: !1,
        isFullscreen: w.value,
        position: e.value.userOptions.position,
        titles: { ...e.value.userOptions.buttonTitles },
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: b.value,
        chartElement: p.value,
        onToggleFullscreen: ue,
        onGeneratePdf: s(j),
        onGenerateImage: s(D),
        onToggleAnnotator: P,
        style: A({
          visibility: s(L) ? s(x) ? "visible" : "hidden" : "visible"
        })
      }, ye({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: _(() => [
            f(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: _(() => [
            f(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: _(({ toggleFullscreen: a, isFullscreen: v }) => [
            f(t.$slots, "optionFullscreen", F(S({ toggleFullscreen: a, isFullscreen: v })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: _(({ toggleAnnotator: a, isAnnotator: v }) => [
            f(t.$slots, "optionAnnotator", F(S({ toggleAnnotator: a, isAnnotator: v })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "position", "titles", "hasAnnotator", "isAnnotation", "chartElement", "onGeneratePdf", "onGenerateImage", "style"])) : h("", !0),
      O.value ? (n(), c("svg", {
        key: 4,
        ref_key: "svgRef",
        ref: se,
        xmlns: s(_e),
        class: z({ "vue-data-ui-fullscreen--on": w.value, "vue-data-ui-fulscreen--off": !w.value }),
        viewBox: `0 0 ${l.value.width <= 0 ? 10 : l.value.width} ${l.value.height <= 0 ? 10 : l.value.height}`,
        style: A(`max-width:100%;overflow:visible;background:transparent;color:${e.value.style.chart.color}`)
      }, [
        fe(ze),
        t.$slots["chart-background"] ? (n(), c("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: l.value.width <= 0 ? 10 : l.value.width,
          height: l.value.height <= 0 ? 10 : l.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          f(t.$slots, "chart-background", {}, void 0, !0)
        ], 8, Le)) : h("", !0),
        e.value.style.chart.layout.wheel.ticks.type === "classic" ? (n(!0), c(J, { key: 1 }, K(q.value, (a, v) => (n(), c("line", {
          x1: a.x1,
          x2: a.x2,
          y1: a.y1,
          y2: a.y2,
          stroke: a.color,
          "stroke-width": e.value.style.chart.layout.wheel.ticks.strokeWidth / 360 * Math.min(l.value.width, l.value.height),
          "stroke-linecap": e.value.style.chart.layout.wheel.ticks.rounded ? "round" : "butt",
          class: z({ "vue-ui-tick-animated": e.value.style.chart.animation.use && v * k.value <= u.value })
        }, null, 10, Be))), 256)) : (n(!0), c(J, { key: 2 }, K(re.value, (a, v) => (n(), c("path", {
          d: a.arcSlice,
          fill: a.color,
          class: z({ "vue-ui-tick-animated": e.value.style.chart.animation.use && v * k.value <= u.value })
        }, null, 10, Ee))), 256)),
        e.value.style.chart.layout.innerCircle.show ? (n(), c("circle", {
          key: 3,
          cx: r.value.centerX,
          cy: r.value.centerY,
          r: r.value.radius * 0.8 <= 0 ? 1e-4 : r.value.radius * 0.8,
          stroke: e.value.style.chart.layout.innerCircle.stroke,
          "stroke-width": e.value.style.chart.layout.innerCircle.strokeWidth,
          fill: "none"
        }, null, 8, Ge)) : h("", !0),
        e.value.style.chart.layout.percentage.show ? (n(), c("text", {
          key: 4,
          x: r.value.centerX,
          y: r.value.centerY + I.value / 3,
          "font-size": I.value,
          fill: e.value.style.chart.layout.wheel.ticks.gradient.show ? s(Q)(e.value.style.chart.layout.wheel.ticks.activeColor, u.value / 100 * (e.value.style.chart.layout.wheel.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.layout.wheel.ticks.activeColor,
          "text-anchor": "middle",
          "font-weight": e.value.style.chart.layout.percentage.bold ? "bold" : "normal",
          style: { "font-variant-numeric": "tabluar-nums" }
        }, pe(s(Oe)(
          e.value.style.chart.layout.percentage.formatter,
          s(Z)(u.value),
          s($e)({
            v: s(Z)(u.value),
            s: "%",
            r: e.value.style.chart.layout.percentage.rounding
          })
        )), 9, je)) : h("", !0),
        f(t.$slots, "svg", { svg: l.value }, void 0, !0)
      ], 14, Xe)) : h("", !0),
      t.$slots.watermark ? (n(), c("div", De, [
        f(t.$slots, "watermark", F(S({ isPrinting: s(E) || s(G) })), void 0, !0)
      ])) : h("", !0),
      t.$slots.source ? (n(), c("div", {
        key: 6,
        ref_key: "source",
        ref: N,
        dir: "auto"
      }, [
        f(t.$slots, "source", {}, void 0, !0)
      ], 512)) : h("", !0),
      O.value ? h("", !0) : (n(), C(Se, {
        key: 7,
        config: {
          type: "wheel",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            wheel: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 44, Re));
  }
}, ot = /* @__PURE__ */ Ue(Ye, [["__scopeId", "data-v-1d726029"]]);
export {
  ot as default
};
