import { computed as s, onMounted as N, ref as A, watch as M, openBlock as n, createElementBlock as i, normalizeStyle as m, toDisplayString as y, createCommentVNode as r, unref as c, createVNode as D, renderSlot as S, createElementVNode as d, normalizeClass as G, createBlock as I } from "vue";
import { u as U, o as q, e as z, g as P, c as R, t as T, N as X, X as H, i as V, v as g, f as Y } from "./index-MWHrTFPq.js";
import { u as O } from "./useNestedProp-CTDeT4KA.js";
import J from "./vue-ui-skeleton-Bo8ydREb.js";
import { _ as K } from "./PackageVersion-CBKqLhAX.js";
const Q = ["xmlns", "viewBox"], W = ["width", "height"], Z = ["id"], ee = ["stop-color"], te = ["stop-color"], ae = ["d", "stroke", "stroke-linecap"], le = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], oe = ["x", "y", "font-size", "fill", "font-weight"], se = {
  key: 4,
  ref: "source",
  dir: "auto"
}, ce = {
  __name: "vue-ui-sparkgauge",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(j) {
    const l = j, { vue_ui_sparkgauge: E } = U(), p = s(() => !!l.dataset && Object.keys(l.dataset).length);
    N(() => {
      h();
    });
    function h() {
      q(l.dataset) ? z({
        componentName: "VueUiSparkgauge",
        type: "dataset"
      }) : P({
        datasetObject: l.dataset,
        requiredAttributes: ["value", "min", "max"]
      }).forEach((t) => {
        z({
          componentName: "VueUiSparkgauge",
          type: "datasetAttribute",
          property: t
        });
      });
    }
    const b = A(R()), e = s({
      get: () => k(),
      set: (t) => t
    });
    function k() {
      const t = O({
        userConfig: l.config,
        defaultConfig: E
      });
      return t.theme ? {
        ...O({
          userConfig: T.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, v = l.dataset.max ?? 0, B = v - t;
      return {
        min: t,
        max: v,
        diff: B
      };
    }), a = A(e.value.style.animation.show ? o.value.min : l.dataset.value);
    M(() => l.dataset.value, () => {
      x(l.dataset.value || 0);
    });
    const _ = s(() => a.value > o.value.max ? o.value.max : a.value < o.value.min ? o.value.min : a.value), $ = s(() => o.value.diff / e.value.style.animation.speedMs);
    N(() => {
      x(l.dataset.value || 0);
    });
    function x(t) {
      function v() {
        a.value < t ? a.value = Math.min(a.value + $.value, t) : a.value > t && (a.value = Math.max(a.value - $.value, t)), a.value !== t && requestAnimationFrame(v);
      }
      v();
    }
    const f = s(() => l.dataset.title ?? ""), w = s(() => a.value >= 0 ? (_.value - o.value.min) / o.value.diff : (Math.abs(o.value.min) - Math.abs(_.value)) / o.value.diff), C = s(() => X(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 ? C.value : e.value.style.dataLabel.color), F = s(() => e.value.style.track.autoColor ? C.value : e.value.style.track.color);
    return (t, v) => (n(), i("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" ? (n(), i("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)) : r("", !0),
      p.value ? (n(), i("svg", {
        key: 1,
        xmlns: c(H),
        viewBox: `0 0 ${u.value.width} ${u.value.height}`,
        style: "overflow: visible; background:transparent; width:100%;"
      }, [
        D(K),
        t.$slots["chart-background"] ? (n(), i("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: u.value.width,
          height: u.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          S(t.$slots, "chart-background")
        ], 8, W)) : r("", !0),
        d("defs", null, [
          d("linearGradient", {
            id: `gradient_${b.value}`,
            x1: "-10%",
            y1: "100%",
            x2: "110%",
            y2: "100%"
          }, [
            d("stop", {
              offset: "0%",
              "stop-color": e.value.style.colors.min
            }, null, 8, ee),
            d("stop", {
              offset: "100%",
              "stop-color": e.value.style.colors.max
            }, null, 8, te)
          ], 8, Z)
        ]),
        d("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, ae),
        w.value !== 0 ? (n(), i("path", {
          key: 1,
          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})` : F.value,
          "stroke-width": 8,
          "stroke-linecap": e.value.style.track.strokeLinecap,
          fill: "none",
          "stroke-dasharray": 169.5,
          "stroke-dashoffset": 169.5 - 169.5 * w.value,
          class: G({ "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, le)) : r("", !0),
        d("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(c(V)(
          e.value.style.dataLabel.formatter,
          c(g)(a.value),
          c(Y)({
            p: e.value.style.dataLabel.prefix,
            v: c(g)(a.value),
            s: e.value.style.dataLabel.suffix,
            r: e.value.style.dataLabel.rounding
          }),
          { datapoint: c(g)(a.value), color: L.value }
        )), 9, oe)
      ], 8, Q)) : r("", !0),
      p.value ? r("", !0) : (n(), I(J, {
        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" ? (n(), i("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)) : r("", !0),
      t.$slots.source ? (n(), i("div", se, [
        S(t.$slots, "source")
      ], 512)) : r("", !0)
    ], 4));
  }
};
export {
  ce as default
};
