import { computed as g, ref as c, watch as oe, onMounted as Fe, onBeforeUnmount as Se, openBlock as s, createElementBlock as u, normalizeClass as se, normalizeStyle as re, createBlock as N, createCommentVNode as f, withCtx as z, toDisplayString as C, unref as v, createSlots as ze, renderSlot as m, normalizeProps as E, guardReactiveProps as T, createVNode as Ce, createElementVNode as y, Fragment as j, renderList as D } from "vue";
import { u as $e, c as Me, t as Pe, a as Oe, p as ne, b as Ie, o as ue, d as Ne, e as X, g as ie, m as ce, X as Xe, s as U, H as A, i as Ae, f as Ye, E as ve } from "./index-Co2zPDEB.js";
import { t as Ge, u as Re } from "./useResponsive-CoxXLe23.js";
import { u as Ee, U as Te } from "./usePrinter-B9fZzpeu.js";
import je from "./vue-ui-skeleton-fxdPT2Rk.js";
import { _ as De } from "./Title-Ct3mhgnX.js";
import { u as de } from "./useNestedProp-BkJbU8lx.js";
import { _ as Ue } from "./PackageVersion-wA829kRV.js";
import { P as Be } from "./PenAndPaper-XIxRCYAM.js";
import { _ as Le } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const We = ["id"], Ve = { key: 0 }, qe = ["xmlns", "viewBox"], He = ["id"], Ze = ["stop-color"], Je = ["stop-color"], Ke = ["stop-color"], Qe = ["id"], et = ["stdDeviation"], tt = ["d", "fill", "stroke"], at = ["d", "filter"], lt = ["x", "y", "text-anchor", "font-size", "font-weight", "fill"], ot = ["x", "y", "font-size", "font-weight", "fill"], st = { key: 1 }, rt = ["x1", "y1", "x2", "y2", "stroke", "stroke-width"], nt = ["x1", "y1", "x2", "y2", "stroke", "stroke-width"], ut = ["x1", "y1", "x2", "y2", "stroke-width", "filter"], it = { key: 2 }, ct = ["d", "fill", "stroke", "stroke-width"], vt = ["cx", "cy", "fill", "r", "stroke-width", "stroke"], dt = ["x", "y", "font-size", "fill"], ht = {
  key: 5,
  class: "vue-data-ui-watermark"
}, ft = {
  __name: "vue-ui-gauge",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(Y, { expose: he }) {
    const r = Y, { vue_ui_gauge: fe } = $e(), $ = g(() => !!r.dataset && Object.keys(r.dataset).length > 0 && r.dataset.series && r.dataset.series.length), k = c(Me()), ye = c(null), B = c(0), w = c(null), L = c(null), W = c(null), V = c(null), q = c(null), H = c(0), e = g({
      get: () => Z(),
      set: (a) => a
    });
    oe(() => r.config, (a) => {
      e.value = Z(), ae(), H.value += 1;
    }, { deep: !0 });
    function Z() {
      const a = de({
        userConfig: r.config,
        defaultConfig: fe
      });
      return a.theme ? {
        ...de({
          userConfig: Pe.vue_ui_gauge[a.theme] || r.config,
          defaultConfig: a
        }),
        customPalette: Oe[a.theme] || ne
      } : a;
    }
    const { isPrinting: J, isImaging: K, generatePdf: Q, generateImage: ee } = Ee({
      elementId: `vue-ui-gauge_${k.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-gauge"
    }), pe = g(() => e.value.userOptions.show && !e.value.style.chart.title.text), ge = g(() => Ie(e.value.customPalette)), _ = g(() => {
      if (!$.value || ue(r.dataset.series || {}))
        return {
          value: 0,
          series: [
            {
              from: 0,
              to: 0
            }
          ]
        };
      const a = [];
      (r.dataset.series || []).forEach((l) => {
        a.push(l.from || 0), a.push(l.to || 0);
      });
      const o = Math.max(...a);
      return {
        ...r.dataset,
        series: (r.dataset.series || []).map((l, n) => ({
          ...l,
          color: Ne(l.color) || ge.value[n] || ne[n],
          value: ((l.to || 0) - (l.from || 0)) / o * 100
        }))
      };
    }), p = c(512), t = c({
      height: 358.4,
      width: p.value,
      top: 0,
      bottom: 358.4,
      centerX: 179.2,
      centerY: p.value / 2,
      labelFontSize: 18,
      legendFontSize: e.value.style.chart.legend.fontSize,
      pointerRadius: e.value.style.chart.layout.pointer.circle.radius,
      trackSize: e.value.style.chart.layout.track.size,
      pointerSize: e.value.style.chart.layout.pointer.size,
      pointerStrokeWidth: e.value.style.chart.layout.pointer.strokeWidth,
      markerOffset: e.value.style.chart.layout.markers.offsetY + 3
    }), M = c(0), F = c(0), d = c(e.value.style.chart.animation.use ? 0 : r.dataset.value);
    oe(() => r.dataset.value, () => {
      le(r.dataset.value);
    });
    const h = g(() => {
      const a = t.value.width / 2, o = i.value.base, l = Math.PI * ((d.value + 0 - F.value) / (M.value - F.value)) + Math.PI;
      return {
        x1: a,
        y1: o,
        x2: a + i.value.pointerSize * t.value.pointerSize * 0.9 * Math.cos(l),
        y2: o + i.value.pointerSize * t.value.pointerSize * 0.9 * Math.sin(l)
      };
    }), te = g(() => {
      const a = t.value.width / 2, o = i.value.base, l = Math.PI * ((d.value + 0 - F.value) / (M.value - F.value)) + Math.PI, n = a + i.value.pointerSize * t.value.pointerSize * 0.9 * Math.cos(l), I = o + i.value.pointerSize * t.value.pointerSize * 0.9 * Math.sin(l), b = t.value.pointerRadius, be = a + b * Math.cos(l + Math.PI / 2), _e = o + b * Math.sin(l + Math.PI / 2), xe = a + b * Math.cos(l - Math.PI / 2), we = o + b * Math.sin(l - Math.PI / 2);
      return isNaN(n) ? null : `M ${n},${I} ${be},${_e} ${xe},${we} Z`;
    }), G = g(() => {
      for (let a = 0; a < _.value.series.length; a += 1) {
        const { color: o, from: l, to: n } = _.value.series[a];
        if (d.value >= l && d.value <= n)
          return o;
      }
      return "#2D353C";
    }), P = c(null);
    function ae() {
      if (ue(r.dataset) ? X({
        componentName: "VueUiGauge",
        type: "dataset"
      }) : (ie({
        datasetObject: r.dataset,
        requiredAttributes: ["value", "series"]
      }).forEach((a) => {
        X({
          componentName: "VueUiGauge",
          type: "datasetAttribute",
          property: a
        });
      }), Object.hasOwn(r.dataset, "series") && (r.dataset.series.length ? r.dataset.series.forEach((a, o) => {
        ie({
          datasetObject: a,
          requiredAttributes: ["from", "to"]
        }).forEach((l) => {
          X({
            componentName: "VueUiGauge",
            type: "datasetSerieAttribute",
            property: l,
            index: o
          });
        });
      }) : X({
        componentName: "VueUiGauge",
        type: "datasetAttributeEmpty",
        property: "series"
      }))), le(r.dataset.value || 0), e.value.responsive) {
        const a = Ge(() => {
          const { width: o, height: l } = Re({
            chart: w.value,
            title: e.value.style.chart.title.text ? L.value : null,
            legend: W.value,
            source: V.value,
            noTitle: q.value
          });
          t.value.width = o, t.value.height = l, t.value.centerX = o / 2, t.value.centerY = p.value / 2 / 358.4 * l, t.value.bottom = l, t.value.labelFontSize = 18 / p.value * Math.min(l, o) < 10 ? 10 : 18 / p.value * Math.min(l, o), t.value.legendFontSize = e.value.style.chart.legend.fontSize / p.value * Math.min(l, o) < 14 ? 14 : e.value.style.chart.legend.fontSize / p.value * Math.min(l, o), t.value.pointerRadius = e.value.style.chart.layout.pointer.circle.radius / p.value * Math.min(l, o), t.value.trackSize = e.value.style.chart.layout.track.size / p.value * Math.min(l, o), t.value.pointerStrokeWidth = ve({
            relator: Math.min(o, l),
            adjuster: p.value,
            source: e.value.style.chart.layout.pointer.strokeWidth,
            threshold: 2,
            fallback: 2
          }), t.value.markerOffset = ve({
            relator: Math.max(o, l),
            adjuster: p.value,
            source: e.value.style.chart.layout.markers.offsetY + 3,
            threshold: 2,
            fallback: 2
          });
        });
        P.value = new ResizeObserver(a), P.value.observe(w.value.parentNode);
      }
    }
    Fe(() => {
      ae();
    }), Se(() => {
      P.value && P.value.disconnect();
    });
    function le(a) {
      const o = [];
      (_.value.series || []).forEach((b) => {
        o.push(b.from || 0), o.push(b.to || 0);
      }), M.value = Math.max(...o), F.value = Math.min(...o);
      let l = e.value.style.chart.animation.speed;
      const n = Math.abs(a - d.value) / (l * 60);
      function I() {
        d.value < a ? d.value = Math.min(d.value + n, a) : d.value > a && (d.value = Math.max(d.value - n, a)), d.value !== a && requestAnimationFrame(I);
      }
      I();
    }
    const i = g(() => {
      const a = e.value.responsive ? Math.min(t.value.width, t.value.height) : t.value.width;
      return {
        arcs: a / 2.5,
        gradients: a / 2.75,
        base: e.value.responsive ? t.value.height / 2 : t.value.height * 0.7,
        ratingBase: e.value.responsive ? t.value.height / 2 + t.value.height / 4 : t.value.height * 0.9,
        pointerSize: e.value.responsive ? Math.min(t.value.width, t.value.height) / 3 : t.value.width / 3.2
      };
    }), x = g(() => ce(
      { series: _.value.series },
      t.value.width / 2,
      i.value.base,
      i.value.arcs,
      i.value.arcs,
      1,
      1,
      1,
      180,
      109.9495,
      40 * t.value.trackSize
    )), me = g(() => ce(
      { series: _.value.series },
      t.value.width / 2,
      i.value.base,
      i.value.gradients,
      i.value.gradients,
      0.95,
      1,
      1,
      180,
      110.02,
      2 * t.value.trackSize
    )), S = c(!1);
    function ke(a) {
      S.value = a, B.value += 1;
    }
    const O = c(!1);
    function R() {
      O.value = !O.value;
    }
    return he({
      generatePdf: Q,
      generateImage: ee,
      toggleAnnotator: R
    }), (a, o) => (s(), u("div", {
      class: se(`vue-ui-gauge ${S.value ? "vue-data-ui-wrapper-fullscreen" : ""}`),
      ref_key: "gaugeChart",
      ref: w,
      id: `vue-ui-gauge_${k.value}`,
      style: re(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height: 100%" : ""}`)
    }, [
      e.value.userOptions.buttons.annotator ? (s(), N(Be, {
        key: 0,
        parent: w.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: O.value,
        onClose: R
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : f("", !0),
      pe.value ? (s(), u("div", {
        key: 1,
        ref_key: "noTitle",
        ref: q,
        class: "vue-data-ui-no-title-space",
        style: "height:36px; width: 100%;background:transparent"
      }, null, 512)) : f("", !0),
      e.value.style.chart.title.text ? (s(), u("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: L,
        style: "width:100%;background:transparent;padding-bottom:12px"
      }, [
        (s(), N(De, {
          key: `title_${H.value}`,
          config: {
            title: {
              cy: "gauge-div-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "gauge-div-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, {
          default: z(() => [
            e.value.translations.base && Y.dataset.base ? (s(), u("span", Ve, C(e.value.translations.base) + ": " + C(Y.dataset.base), 1)) : f("", !0)
          ]),
          _: 1
        }, 8, ["config"]))
      ], 512)) : f("", !0),
      e.value.userOptions.show && $.value ? (s(), N(Te, {
        ref_key: "details",
        ref: ye,
        key: `user_options_${B.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isImaging: v(K),
        isPrinting: v(J),
        uid: k.value,
        hasXls: !1,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasImg: e.value.userOptions.buttons.img,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        isFullscreen: S.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: w.value,
        position: e.value.userOptions.position,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: O.value,
        onToggleFullscreen: ke,
        onGeneratePdf: v(Q),
        onGenerateImage: v(ee),
        onToggleAnnotator: R
      }, ze({ _: 2 }, [
        a.$slots.optionPdf ? {
          name: "optionPdf",
          fn: z(() => [
            m(a.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        a.$slots.optionImg ? {
          name: "optionImg",
          fn: z(() => [
            m(a.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        a.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: z(({ toggleFullscreen: l, isFullscreen: n }) => [
            m(a.$slots, "optionFullscreen", E(T({ toggleFullscreen: l, isFullscreen: n })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        a.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: z(({ toggleAnnotator: l, isAnnotator: n }) => [
            m(a.$slots, "optionAnnotator", E(T({ toggleAnnotator: l, isAnnotator: n })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isImaging", "isPrinting", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage"])) : f("", !0),
      $.value ? (s(), u("svg", {
        key: 4,
        xmlns: v(Xe),
        class: se({ "vue-data-ui-fullscreen--on": S.value, "vue-data-ui-fulscreen--off": !S.value }),
        viewBox: `0 0 ${t.value.width <= 0 ? 10 : t.value.width} ${t.value.height <= 0 ? 10 : t.value.height}`,
        style: re(`max-width:100%;overflow:hidden !important;background:transparent;color:${e.value.style.chart.color}`)
      }, [
        Ce(Ue),
        y("defs", null, [
          y("radialGradient", {
            id: `gradient_${k.value}`,
            cx: "50%",
            cy: "50%",
            r: "50%",
            fx: "50%",
            fy: "50%"
          }, [
            y("stop", {
              offset: "0%",
              "stop-color": v(U)("#FFFFFF", 1)
            }, null, 8, Ze),
            y("stop", {
              offset: "80%",
              "stop-color": v(U)("#FFFFFF", e.value.style.chart.layout.track.gradientIntensity)
            }, null, 8, Je),
            y("stop", {
              offset: "100%",
              "stop-color": v(U)("#FFFFFF", 1)
            }, null, 8, Ke)
          ], 8, He)
        ]),
        y("defs", null, [
          y("filter", {
            id: `blur_${k.value}`,
            x: "-50%",
            y: "-50%",
            width: "200%",
            height: "200%"
          }, [
            y("feGaussianBlur", {
              in: "SourceGraphic",
              stdDeviation: 100 / e.value.style.chart.layout.track.gradientIntensity
            }, null, 8, et)
          ], 8, Qe)
        ]),
        (s(!0), u(j, null, D(x.value, (l, n) => (s(), u("path", {
          key: `arc_${n}`,
          d: l.arcSlice,
          fill: l.color,
          stroke: e.value.style.chart.backgroundColor,
          "stroke-linecap": "round"
        }, null, 8, tt))), 128)),
        e.value.style.chart.layout.track.useGradient ? (s(!0), u(j, { key: 0 }, D(me.value, (l, n) => (s(), u("path", {
          key: `arc_${n}`,
          d: l.arcSlice,
          fill: "#FFFFFF",
          stroke: "none",
          "stroke-linecap": "round",
          filter: `url(#blur_${k.value})`
        }, null, 8, at))), 128)) : f("", !0),
        (s(!0), u(j, null, D(x.value, (l, n) => (s(), u("text", {
          x: v(A)({
            centerX: t.value.width / 2,
            centerY: i.value.base,
            initX: l.center.startX,
            initY: l.center.startY,
            offset: t.value.markerOffset
          }).x,
          y: v(A)({
            centerX: t.value.width / 2,
            centerY: i.value.base,
            initX: l.center.startX,
            initY: l.center.startY,
            offset: t.value.markerOffset
          }).y,
          "text-anchor": l.center.startX < t.value.width / 2 - 5 ? "end" : l.center.startX > t.value.width / 2 + 5 ? "start" : "middle",
          "font-size": t.value.labelFontSize * e.value.style.chart.layout.markers.fontSizeRatio,
          "font-weight": `${e.value.style.chart.layout.markers.bold ? "bold" : "normal"}`,
          fill: e.value.style.chart.layout.markers.color
        }, C(l.from.toFixed(e.value.style.chart.layout.markers.roundingValue)), 9, lt))), 256)),
        y("text", {
          x: v(A)({
            centerX: t.value.width / 2,
            centerY: i.value.base,
            initX: x.value.at(-1).endX,
            initY: x.value.at(-1).endY,
            offset: t.value.markerOffset
          }).x,
          y: v(A)({
            centerX: t.value.width / 2,
            centerY: i.value.base,
            initX: x.value.at(-1).endX,
            initY: x.value.at(-1).endY,
            offset: t.value.markerOffset
          }).y,
          "text-anchor": "start",
          "font-size": t.value.labelFontSize * e.value.style.chart.layout.markers.fontSizeRatio,
          "font-weight": `${e.value.style.chart.layout.markers.bold ? "bold" : "normal"}`,
          fill: e.value.style.chart.layout.markers.color
        }, C(M.value.toFixed(e.value.style.chart.layout.markers.roundingValue)), 9, ot),
        e.value.style.chart.layout.pointer.type === "rounded" ? (s(), u("g", st, [
          isNaN(h.value.x2) ? f("", !0) : (s(), u("line", {
            key: 0,
            x1: h.value.x1,
            y1: h.value.y1,
            x2: h.value.x2,
            y2: h.value.y2,
            stroke: e.value.style.chart.layout.pointer.stroke,
            "stroke-width": t.value.pointerStrokeWidth,
            "stroke-linecap": "round"
          }, null, 8, rt)),
          isNaN(h.value.x2) ? f("", !0) : (s(), u("line", {
            key: 1,
            x1: h.value.x1,
            y1: h.value.y1,
            x2: h.value.x2,
            y2: h.value.y2,
            stroke: e.value.style.chart.layout.pointer.useRatingColor ? G.value : e.value.style.chart.layout.pointer.color,
            "stroke-linecap": "round",
            "stroke-width": t.value.pointerStrokeWidth * 0.7
          }, null, 8, nt)),
          !isNaN(h.value.x2) && e.value.style.chart.layout.track.useGradient ? (s(), u("line", {
            key: 2,
            x1: h.value.x1,
            y1: h.value.y1,
            x2: h.value.x2,
            y2: h.value.y2,
            stroke: "white",
            "stroke-linecap": "round",
            "stroke-width": t.value.pointerStrokeWidth * 0.3,
            filter: `url(#blur_${k.value})`
          }, null, 8, ut)) : f("", !0)
        ])) : (s(), u("g", it, [
          te.value ? (s(), u("path", {
            key: 0,
            d: te.value,
            fill: e.value.style.chart.layout.pointer.useRatingColor ? G.value : e.value.style.chart.layout.pointer.color,
            stroke: e.value.style.chart.layout.pointer.stroke,
            "stroke-width": e.value.style.chart.layout.pointer.circle.strokeWidth,
            "stroke-linejoin": "round"
          }, null, 8, ct)) : f("", !0)
        ])),
        y("circle", {
          cx: t.value.width / 2,
          cy: i.value.base,
          fill: e.value.style.chart.layout.pointer.circle.color,
          r: t.value.pointerRadius <= 0 ? 1e-4 : t.value.pointerRadius,
          "stroke-width": e.value.style.chart.layout.pointer.circle.strokeWidth,
          stroke: e.value.style.chart.layout.pointer.circle.stroke
        }, null, 8, vt),
        y("text", {
          x: t.value.width / 2,
          y: i.value.ratingBase,
          "text-anchor": "middle",
          "font-size": t.value.legendFontSize,
          "font-weight": "bold",
          fill: e.value.style.chart.legend.useRatingColor ? G.value : e.value.style.chart.legend.color
        }, C(v(Ae)(
          e.value.style.chart.legend.formatter,
          d.value,
          v(Ye)({
            p: e.value.style.chart.legend.prefix + (e.value.style.chart.legend.showPlusSymbol && d.value > 0 ? "+" : ""),
            v: d.value,
            s: e.value.style.chart.legend.suffix,
            r: e.value.style.chart.legend.roundingValue
          })
        )), 9, dt),
        m(a.$slots, "svg", { svg: t.value }, void 0, !0)
      ], 14, qe)) : f("", !0),
      a.$slots.watermark ? (s(), u("div", ht, [
        m(a.$slots, "watermark", E(T({ isPrinting: v(J) || v(K) })), void 0, !0)
      ])) : f("", !0),
      $.value ? f("", !0) : (s(), N(je, {
        key: 6,
        config: {
          type: "gauge",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            gauge: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      y("div", {
        ref_key: "chartLegend",
        ref: W
      }, [
        m(a.$slots, "legend", { legend: _.value }, void 0, !0)
      ], 512),
      a.$slots.source ? (s(), u("div", {
        key: 7,
        ref_key: "source",
        ref: V,
        dir: "auto"
      }, [
        m(a.$slots, "source", {}, void 0, !0)
      ], 512)) : f("", !0)
    ], 14, We));
  }
}, St = /* @__PURE__ */ Le(ft, [["__scopeId", "data-v-1082d899"]]);
export {
  St as default
};
