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