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