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 v, unref as c, createVNode as D, createElementVNode as d, normalizeClass as E, createBlock as G, renderSlot as I } from "vue";
import { u as U, o as q, e as S, g as P, c as R, t as T, N as X, X as H, i as V, v as p, f as Y } from "./index-Cm2_6s9o.js";
import { u as z } from "./useNestedProp-BYPZJNhi.js";
import J from "./vue-ui-skeleton-BUS6A44x.js";
import { _ as K } from "./PackageVersion-CTMY4zeY.js";
const Q = ["xmlns", "viewBox"], W = ["id"], Z = ["stop-color"], ee = ["stop-color"], te = ["d", "stroke", "stroke-linecap"], ae = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], le = ["x", "y", "font-size", "fill", "font-weight"], oe = {
  key: 4,
  ref: "source",
  dir: "auto"
}, ve = {
  __name: "vue-ui-sparkgauge",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(F) {
    const l = F, { vue_ui_sparkgauge: O } = U(), g = s(() => !!l.dataset && Object.keys(l.dataset).length);
    N(() => {
      h();
    });
    function h() {
      q(l.dataset) ? S({
        componentName: "VueUiSparkgauge",
        type: "dataset"
      }) : P({
        datasetObject: l.dataset,
        requiredAttributes: ["value", "min", "max"]
      }).forEach((t) => {
        S({
          componentName: "VueUiSparkgauge",
          type: "datasetAttribute",
          property: t
        });
      });
    }
    const b = A(R()), e = s({
      get: () => k(),
      set: (t) => t
    });
    function k() {
      const t = z({
        userConfig: l.config,
        defaultConfig: O
      });
      return t.theme ? {
        ...z({
          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, r = l.dataset.max ?? 0, B = r - t;
      return {
        min: t,
        max: r,
        diff: B
      };
    }), a = A(e.value.style.animation.show ? o.value.min : l.dataset.value);
    M(() => l.dataset.value, () => {
      $(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(() => {
      $(l.dataset.value || 0);
    });
    function $(t) {
      function r() {
        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(r);
      }
      r();
    }
    const f = s(() => l.dataset.title ?? ""), C = s(() => a.value >= 0 ? (_.value - o.value.min) / o.value.diff : (Math.abs(o.value.min) - Math.abs(_.value)) / o.value.diff), w = 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 ? w.value : e.value.style.dataLabel.color), j = s(() => e.value.style.track.autoColor ? w.value : e.value.style.track.color);
    return (t, r) => (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)) : v("", !0),
      g.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),
        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, Z),
            d("stop", {
              offset: "100%",
              "stop-color": e.value.style.colors.max
            }, null, 8, ee)
          ], 8, W)
        ]),
        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, te),
        C.value !== 0 ? (n(), i("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 * C.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, ae)) : v("", !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(p)(a.value),
          c(Y)({
            p: e.value.style.dataLabel.prefix,
            v: c(p)(a.value),
            s: e.value.style.dataLabel.suffix,
            r: e.value.style.dataLabel.rounding
          }),
          { datapoint: c(p)(a.value), color: L.value }
        )), 9, le)
      ], 8, Q)) : v("", !0),
      g.value ? v("", !0) : (n(), G(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)) : v("", !0),
      t.$slots.source ? (n(), i("div", oe, [
        I(t.$slots, "source")
      ], 512)) : v("", !0)
    ], 4));
  }
};
export {
  ve as default
};
