import { computed as s, onMounted as C, ref as y, watch as O, openBlock as n, createElementBlock as v, normalizeStyle as c, toDisplayString as g, createCommentVNode as d, unref as i, createElementVNode as r, normalizeClass as j, createBlock as B } from "vue";
import { u as D, o as E, e as L, g as G, c as I, t as U, L as V, X as q, i as P, s as p, f as T } from "./index-CguVaFlt.js";
import { u as A } from "./useNestedProp-BbEbJmgv.js";
import X from "./vue-ui-skeleton-ChHLL5Hw.js";
const H = ["xmlns", "viewBox"], R = ["id"], Y = ["stop-color"], J = ["stop-color"], K = ["d", "stroke", "stroke-linecap"], Q = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], W = ["x", "y", "font-size", "fill", "font-weight"], le = {
  __name: "vue-ui-sparkgauge",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(N) {
    const t = N, { vue_ui_sparkgauge: S } = D(), b = s(() => !!t.dataset && Object.keys(t.dataset).length);
    C(() => {
      E(t.dataset) ? L({
        componentName: "VueUiSparkgauge",
        type: "dataset"
      }) : G({
        datasetObject: t.dataset,
        requiredAttributes: ["value", "min", "max"]
      }).forEach((o) => {
        L({
          componentName: "VueUiSparkgauge",
          type: "datasetAttribute",
          property: o
        });
      });
    });
    const h = y(I()), e = s(() => {
      const o = A({
        userConfig: t.config,
        defaultConfig: S
      });
      return o.theme ? {
        ...A({
          userConfig: U.vue_ui_sparkgauge[o.theme] || t.config,
          defaultConfig: o
        })
      } : o;
    }), u = s(() => ({
      height: e.value.style.height,
      width: 128,
      base: e.value.style.basePosition
    })), a = s(() => {
      const o = t.dataset.min ?? 0, m = t.dataset.max ?? 0, F = m - o;
      return {
        min: o,
        max: m,
        diff: F
      };
    }), l = y(e.value.style.animation.show ? a.value.min : t.dataset.value);
    O(() => t.dataset.value, () => {
      l.value = y(e.value.style.animation.show ? a.value.min : t.dataset.value), x();
    });
    const k = s(() => l.value > a.value.max ? a.value.max : l.value < a.value.min ? a.value.min : l.value), z = s(() => a.value.diff / e.value.style.animation.speedMs);
    C(() => {
      x();
    });
    function x() {
      function o() {
        l.value += z.value, l.value < t.dataset.value ? requestAnimationFrame(o) : l.value = t.dataset.value;
      }
      e.value.style.animation.show && (l.value = a.value.min, o());
    }
    const f = s(() => t.dataset.title ?? ""), _ = s(() => l.value >= 0 ? (k.value - a.value.min) / a.value.diff : (Math.abs(a.value.min) - Math.abs(k.value)) / a.value.diff), $ = s(() => V(e.value.style.colors.min, e.value.style.colors.max, a.value.min, a.value.max, l.value)), w = s(() => e.value.style.dataLabel.autoColor ? $.value : e.value.style.dataLabel.color), M = s(() => e.value.style.track.autoColor ? $.value : e.value.style.track.color);
    return (o, m) => (n(), v("div", {
      style: c(`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(), v("div", {
        key: 0,
        class: "vue-data-ui-sparkgauge-label",
        style: c(`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}`)
      }, g(f.value), 5)) : d("", !0),
      b.value ? (n(), v("svg", {
        key: 1,
        xmlns: i(q),
        viewBox: `0 0 ${u.value.width} ${u.value.height}`,
        style: c(`overflow: visible; background:${e.value.style.background}; width:100%;`)
      }, [
        r("defs", null, [
          r("linearGradient", {
            id: `gradient_${h.value}`,
            x1: "-10%",
            y1: "100%",
            x2: "110%",
            y2: "100%"
          }, [
            r("stop", {
              offset: "0%",
              "stop-color": e.value.style.colors.min
            }, null, 8, Y),
            r("stop", {
              offset: "100%",
              "stop-color": e.value.style.colors.max
            }, null, 8, J)
          ], 8, R)
        ]),
        r("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, K),
        _.value !== 0 ? (n(), v("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_${h.value})` : M.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: j({ "vue-ui-sparkgauge-track": e.value.style.animation.show }),
          style: c(e.value.style.animation.show ? `animation: vue-ui-sparkgauge-animation ${e.value.style.animation.speedMs}ms ease-in;` : "")
        }, null, 14, Q)) : d("", !0),
        r("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: w.value,
          "font-weight": e.value.style.dataLabel.bold ? "bold" : "normal"
        }, g(i(P)(
          e.value.style.dataLabel.formatter,
          i(p)(l.value),
          i(T)({
            p: e.value.style.dataLabel.prefix,
            v: i(p)(l.value),
            s: e.value.style.dataLabel.suffix,
            r: e.value.style.dataLabel.rounding
          }),
          { datapoint: i(p)(l.value), color: w.value }
        )), 9, W)
      ], 12, H)) : d("", !0),
      b.value ? d("", !0) : (n(), B(X, {
        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(), v("div", {
        key: 3,
        class: "vue-data-ui-sparkgauge-label",
        style: c(`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}`)
      }, g(f.value), 5)) : d("", !0)
    ], 4));
  }
};
export {
  le as default
};
