import { computed as s, onMounted as N, ref as A, watch as M, openBlock as i, createElementBlock as c, normalizeStyle as m, toDisplayString as y, createCommentVNode as d, unref as r, createVNode as D, createElementVNode as v, normalizeClass as E, createBlock as G } from "vue";
import { u as I, o as U, e as S, g as q, c as P, t as R, N as T, X, i as H, v as p, f as V } from "./index-DK7qqHGP.js";
import { u as z } from "./useNestedProp-0nRX_rTi.js";
import Y from "./vue-ui-skeleton-CQnYuosp.js";
import { _ as J } from "./PackageVersion-I1_4jcn_.js";
const K = ["xmlns", "viewBox"], Q = ["id"], W = ["stop-color"], Z = ["stop-color"], ee = ["d", "stroke", "stroke-linecap"], te = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], ae = ["x", "y", "font-size", "fill", "font-weight"], ie = {
  __name: "vue-ui-sparkgauge",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(F) {
    const l = F, { vue_ui_sparkgauge: O } = I(), g = s(() => !!l.dataset && Object.keys(l.dataset).length);
    N(() => {
      h();
    });
    function h() {
      U(l.dataset) ? S({
        componentName: "VueUiSparkgauge",
        type: "dataset"
      }) : q({
        datasetObject: l.dataset,
        requiredAttributes: ["value", "min", "max"]
      }).forEach((t) => {
        S({
          componentName: "VueUiSparkgauge",
          type: "datasetAttribute",
          property: t
        });
      });
    }
    const b = A(P()), e = s({
      get: () => k(),
      set: (t) => t
    });
    function k() {
      const t = z({
        userConfig: l.config,
        defaultConfig: O
      });
      return t.theme ? {
        ...z({
          userConfig: R.vue_ui_sparkgauge[t.theme] || l.config,
          defaultConfig: t
        })
      } : t;
    }
    M(() => l.config, (t) => {
      e.value = k(), h();
    }, { deep: !0 });
    const u = s(() => ({
      height: e.value.style.height,
      width: 128,
      base: e.value.style.basePosition
    })), o = s(() => {
      const t = l.dataset.min ?? 0, n = l.dataset.max ?? 0, B = n - t;
      return {
        min: t,
        max: n,
        diff: B
      };
    }), a = A(e.value.style.animation.show ? o.value.min : l.dataset.value);
    M(() => l.dataset.value, () => {
      C(l.dataset.value || 0);
    });
    const _ = s(() => a.value > o.value.max ? o.value.max : a.value < o.value.min ? o.value.min : a.value), x = s(() => o.value.diff / e.value.style.animation.speedMs);
    N(() => {
      C(l.dataset.value || 0);
    });
    function C(t) {
      function n() {
        a.value < t ? a.value = Math.min(a.value + x.value, t) : a.value > t && (a.value = Math.max(a.value - x.value, t)), a.value !== t && requestAnimationFrame(n);
      }
      n();
    }
    const f = s(() => l.dataset.title ?? ""), $ = s(() => a.value >= 0 ? (_.value - o.value.min) / o.value.diff : (Math.abs(o.value.min) - Math.abs(_.value)) / o.value.diff), w = s(() => T(e.value.style.colors.min, e.value.style.colors.max, o.value.min, o.value.max, a.value)), L = s(() => e.value.style.dataLabel.autoColor ? w.value : e.value.style.dataLabel.color), j = s(() => e.value.style.track.autoColor ? w.value : e.value.style.track.color);
    return (t, n) => (i(), c("div", {
      style: m(`font-family:${e.value.style.fontFamily};width: 100%; background:${e.value.style.background}`)
    }, [
      e.value.style.title.show && f.value && e.value.style.title.position === "top" ? (i(), c("div", {
        key: 0,
        class: "vue-data-ui-sparkgauge-label",
        style: m(`font-size:${e.value.style.title.fontSize}px;text-align:${e.value.style.title.textAlign};font-weight:${e.value.style.title.bold ? "bold" : "normal"};color:${e.value.style.title.color}`)
      }, y(f.value), 5)) : d("", !0),
      g.value ? (i(), c("svg", {
        key: 1,
        xmlns: r(X),
        viewBox: `0 0 ${u.value.width} ${u.value.height}`,
        style: "overflow: visible; background:transparent; width:100%;"
      }, [
        D(J),
        v("defs", null, [
          v("linearGradient", {
            id: `gradient_${b.value}`,
            x1: "-10%",
            y1: "100%",
            x2: "110%",
            y2: "100%"
          }, [
            v("stop", {
              offset: "0%",
              "stop-color": e.value.style.colors.min
            }, null, 8, W),
            v("stop", {
              offset: "100%",
              "stop-color": e.value.style.colors.max
            }, null, 8, Z)
          ], 8, Q)
        ]),
        v("path", {
          d: `M10 ${u.value.base} A 1 1 0 1 1 118 ${u.value.base}`,
          stroke: e.value.style.gutter.color,
          "stroke-width": 8,
          "stroke-linecap": e.value.style.gutter.strokeLinecap,
          fill: "none"
        }, null, 8, ee),
        $.value !== 0 ? (i(), c("path", {
          key: 0,
          d: `M10 ${u.value.base} A 1 1 0 1 1 118 ${u.value.base}`,
          stroke: e.value.style.colors.showGradient ? `url(#gradient_${b.value})` : j.value,
          "stroke-width": 8,
          "stroke-linecap": e.value.style.track.strokeLinecap,
          fill: "none",
          "stroke-dasharray": 169.5,
          "stroke-dashoffset": 169.5 - 169.5 * $.value,
          class: E({ "vue-ui-sparkgauge-track": e.value.style.animation.show }),
          style: m(e.value.style.animation.show ? `animation: vue-ui-sparkgauge-animation ${e.value.style.animation.speedMs}ms ease-in;` : "")
        }, null, 14, te)) : d("", !0),
        v("text", {
          "text-anchor": "middle",
          x: u.value.width / 2,
          y: u.value.base + 6 + e.value.style.dataLabel.offsetY,
          "font-size": e.value.style.dataLabel.fontSize,
          fill: L.value,
          "font-weight": e.value.style.dataLabel.bold ? "bold" : "normal"
        }, y(r(H)(
          e.value.style.dataLabel.formatter,
          r(p)(a.value),
          r(V)({
            p: e.value.style.dataLabel.prefix,
            v: r(p)(a.value),
            s: e.value.style.dataLabel.suffix,
            r: e.value.style.dataLabel.rounding
          }),
          { datapoint: r(p)(a.value), color: L.value }
        )), 9, ae)
      ], 8, K)) : d("", !0),
      g.value ? d("", !0) : (i(), G(Y, {
        key: 2,
        config: {
          type: "gauge",
          style: {
            backgroundColor: e.value.style.background,
            gauge: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      e.value.style.title.show && f.value && e.value.style.title.position === "bottom" ? (i(), c("div", {
        key: 3,
        class: "vue-data-ui-sparkgauge-label",
        style: m(`font-size:${e.value.style.title.fontSize}px;text-align:${e.value.style.title.textAlign};font-weight:${e.value.style.title.bold ? "bold" : "normal"};font-weight:${e.value.style.title.bold ? "bold" : "normal"};color:${e.value.style.title.color}`)
      }, y(f.value), 5)) : d("", !0)
    ], 4));
  }
};
export {
  ie as default
};
