import { computed as u, ref as g, watch as A, onMounted as Z, openBlock as s, createElementBlock as i, normalizeStyle as H, createBlock as C, unref as c, createVNode as J, createElementVNode as k, createCommentVNode as v, toDisplayString as B } from "vue";
import { u as K, c as Q, t as Y, o as ee, e as te, v as y, V as ae, X as le, s as z, R as D, f as E, i as ne } from "./index-DK7qqHGP.js";
import { u as G } from "./useNestedProp-0nRX_rTi.js";
import M from "./BaseIcon-ZChy8GeS.js";
import oe from "./vue-ui-skeleton-CQnYuosp.js";
import { _ as se } from "./PackageVersion-I1_4jcn_.js";
import { _ as ue } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const re = ["id"], ie = ["xmlns", "viewBox"], de = ["id"], ve = ["stop-color"], ce = ["stop-color"], ye = { key: 0 }, he = ["d", "fill"], fe = ["d", "fill"], pe = ["d", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin"], me = ["d", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin"], ge = ["height", "width", "x"], ke = { style: { width: "100%" } }, _e = ["x", "y", "fill", "font-size", "font-weight"], be = ["stroke", "cx", "cy", "fill"], xe = ["x", "y", "font-size", "fill", "font-weight"], we = {
  __name: "vue-ui-spark-trend",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(O) {
    const n = O, { vue_ui_spark_trend: U } = K(), q = u(() => !!n.dataset && n.dataset.length), _ = g(Q()), e = u({
      get: () => S(),
      set: (t) => t
    });
    function S() {
      const t = G({
        userConfig: n.config,
        defaultConfig: U
      });
      return t.theme ? {
        ...G({
          userConfig: Y.vue_ui_spark_trend[t.theme] || n.config,
          defaultConfig: t
        })
      } : t;
    }
    A(() => n.config, (t) => {
      e.value = S(), I();
    }, { deep: !0 }), A(() => n.dataset, (t) => {
      p.value = n.dataset.map((l) => [void 0, 1 / 0, -1 / 0, null, NaN].includes(l) ? null : l);
    }, { deep: !0 });
    function L(t) {
      return t.map((l) => y(l));
    }
    const p = g(n.dataset.map((t) => e.value.style.animation.show || [void 0, 1 / 0, -1 / 0, null, NaN].includes(t) ? null : t)), m = g(!1), N = g(null);
    Z(() => {
      I();
      let l = 1e3 / e.value.style.animation.animationFrames, d = performance.now();
      if (e.value.style.animation.show && e.value.style.animation.animationFrames && n.dataset.length > 1) {
        let T = function() {
          m.value = !0;
          let j = performance.now(), V = j - d;
          V > l ? (d = j - V % l, f < n.dataset.length ? (p.value.push(n.dataset[f]), f += 1, N.value = requestAnimationFrame(T)) : (cancelAnimationFrame(N.value), p.value = L(n.dataset), m.value = !1)) : N.value = requestAnimationFrame(T);
        };
        p.value = [];
        let f = 0;
        T();
      }
    });
    function I() {
      ee(n.dataset) && te({
        componentName: "VueUiSparkTrend",
        type: "dataset"
      });
    }
    const o = g({
      height: 80,
      width: 300
    }), h = u(() => ({
      top: e.value.style.padding.top,
      left: e.value.style.padding.left,
      right: o.value.width - e.value.style.padding.right,
      bottom: o.value.height - e.value.style.padding.bottom,
      height: o.value.height - (e.value.style.padding.top + e.value.style.padding.bottom) - (e.value.style.dataLabel.show ? e.value.style.dataLabel.fontSize : 0),
      width: o.value.width - (e.value.style.padding.left + e.value.style.padding.right)
    })), $ = u(() => {
      const t = L(n.dataset);
      return {
        max: Math.max(...t.map((l) => y(l))),
        min: Math.min(...t.map((l) => y(l)))
      };
    }), b = u(() => {
      const t = $.value.min >= 0 ? 0 : $.value.min;
      return Math.abs(t);
    }), P = u(() => $.value.max + b.value);
    function F(t) {
      return t / P.value;
    }
    const R = u(() => n.dataset.length), a = u(() => p.value.map((t, l) => {
      const d = isNaN(t) || [void 0, null, "NaN", NaN, 1 / 0, -1 / 0].includes(t) ? 0 : t || 0;
      return {
        value: y(t),
        absoluteValue: y(d),
        plotValue: y(d + b.value),
        toMax: F(d + b.value),
        x: h.value.left + y(l * (h.value.width / (R.value - 1))) - e.value.style.padding.right,
        y: h.value.bottom - y(h.value.height * F(d + b.value))
      };
    })), x = u(() => {
      const t = L(n.dataset);
      return e.value.style.trendLabel.trendType === "global" ? ae(t) : e.value.style.trendLabel.trendType === "n-1" && t.length > 1 ? (t.at(-1) / t.at(-2) - 1) * 100 : e.value.style.trendLabel.trendType === "lastToFirst" ? (t.at(-1) / t[0] - 1) * 100 : 0;
    }), w = u(() => m.value || x.value === 0 ? "neutral" : x.value > 0 ? "positive" : "negative"), r = u(() => e.value.style.arrow.colors[w.value]), W = u(() => {
      const t = { x: a.value[0].x, y: o.value.height - 6 }, l = { x: a.value[a.value.length - 1].x, y: o.value.height - 6 }, d = [];
      return a.value.forEach((f) => {
        d.push(`${f.x},${f.y} `);
      }), [t.x, t.y, ...d, l.x, l.y].toString();
    }), X = u(() => {
      let t = [];
      return a.value.forEach((l) => {
        t.push(`${l.x},${l.y} `);
      }), `M ${t.toString()}`;
    });
    return (t, l) => (s(), i("div", {
      class: "vue-ui-spark-trend",
      id: _.value,
      style: H(`width:100%;font-family:${e.value.style.fontFamily};background:${e.value.style.backgroundColor}`)
    }, [
      q.value ? (s(), i("svg", {
        key: 1,
        xmlns: c(le),
        viewBox: `0 0 ${o.value.width} ${o.value.height}`,
        style: "width:100%;background:transparent;overflow:visible"
      }, [
        J(se),
        k("defs", null, [
          k("linearGradient", {
            x1: "0%",
            y1: "0%",
            x2: "0%",
            y2: "100%",
            id: `pill_gradient_${_.value}`
          }, [
            k("stop", {
              offset: "0%",
              "stop-color": c(z)(e.value.style.line.useColorTrend ? r.value : e.value.style.line.stroke, e.value.style.area.opacity)
            }, null, 8, ve),
            k("stop", {
              offset: "100%",
              "stop-color": e.value.style.backgroundColor
            }, null, 8, ce)
          ], 8, de)
        ]),
        e.value.style.area.show && a.value[0] ? (s(), i("g", ye, [
          e.value.style.line.smooth ? (s(), i("path", {
            key: 0,
            d: `M ${a.value[0].x},${h.value.bottom} ${c(D)(a.value)} L ${a.value.at(-1).x},${h.value.bottom} Z`,
            fill: e.value.style.area.useGradient ? `url(#pill_gradient_${_.value})` : c(z)(e.value.style.line.useColorTrend ? r.value : e.value.style.line.stroke, e.value.style.area.opacity),
            stroke: "none"
          }, null, 8, he)) : (s(), i("path", {
            key: 1,
            d: `M${W.value}Z`,
            fill: e.value.style.area.useGradient ? `url(#pill_gradient_${_.value})` : c(z)(e.value.style.line.useColorTrend ? r.value : e.value.style.line.stroke, e.value.style.area.opacity),
            stroke: "none"
          }, null, 8, fe))
        ])) : v("", !0),
        e.value.style.line.smooth && a.value.length ? (s(), i("path", {
          key: 1,
          d: `M ${c(D)(a.value)}`,
          stroke: e.value.style.line.useColorTrend ? r.value : e.value.style.line.stroke,
          fill: "none",
          "stroke-width": e.value.style.line.strokeWidth,
          "stroke-linecap": e.value.style.line.strokeLinecap,
          "stroke-linejoin": e.value.style.line.strokeLinejoin
        }, null, 8, pe)) : v("", !0),
        !e.value.style.line.smooth && a.value.length ? (s(), i("path", {
          key: 2,
          d: X.value,
          stroke: e.value.style.line.useColorTrend ? r.value : e.value.style.line.stroke,
          fill: "none",
          "stroke-width": e.value.style.line.strokeWidth,
          "stroke-linecap": e.value.style.line.strokeLinecap,
          "stroke-linejoin": e.value.style.line.strokeLinejoin
        }, null, 8, me)) : v("", !0),
        m.value ? v("", !0) : (s(), i("foreignObject", {
          key: 3,
          height: o.value.height / 2,
          width: o.value.height / 2,
          x: o.value.height / 5,
          y: 8
        }, [
          k("div", ke, [
            w.value === "positive" ? (s(), C(M, {
              key: 0,
              stroke: r.value,
              name: "arrowTop",
              size: o.value.height / 2
            }, null, 8, ["stroke", "size"])) : v("", !0),
            w.value === "negative" ? (s(), C(M, {
              key: 1,
              stroke: r.value,
              name: "arrowBottom",
              size: o.value.height / 2
            }, null, 8, ["stroke", "size"])) : v("", !0),
            w.value === "neutral" ? (s(), C(M, {
              key: 2,
              stroke: r.value,
              name: "arrowRight",
              size: o.value.height / 2
            }, null, 8, ["stroke", "size"])) : v("", !0)
          ])
        ], 8, ge)),
        m.value ? v("", !0) : (s(), i("text", {
          key: 4,
          x: o.value.height / 2 - o.value.height / 20,
          y: h.value.bottom,
          "text-anchor": "middle",
          fill: e.value.style.trendLabel.useColorTrend ? r.value : e.value.style.trendLabel.color,
          "font-size": e.value.style.trendLabel.fontSize,
          "font-weight": e.value.style.trendLabel.bold ? "bold" : "normal"
        }, B(c(E)({
          p: x.value > 0 ? "+" : "",
          v: x.value,
          s: "%",
          r: e.value.style.trendLabel.rounding
        })), 9, _e)),
        a.value.length && a.value.at(-1).x !== void 0 ? (s(), i("circle", {
          key: 5,
          stroke: e.value.style.backgroundColor,
          "stroke-width": 2,
          cx: a.value.at(-1).x,
          cy: a.value.at(-1).y,
          r: 4,
          fill: r.value
        }, null, 8, be)) : v("", !0),
        a.value.length && a.value.at(-1).x !== void 0 && e.value.style.dataLabel.show ? (s(), i("text", {
          key: 6,
          "text-anchor": "middle",
          x: a.value.at(-1).x,
          y: a.value.at(-1).y - e.value.style.dataLabel.fontSize / 1.5,
          "font-size": e.value.style.dataLabel.fontSize,
          fill: e.value.style.dataLabel.useColorTrend ? r.value : e.value.style.dataLabel.color,
          "font-weight": e.value.style.dataLabel.bold ? "bold" : "normal"
        }, B(c(ne)(
          e.value.style.dataLabel.formatter,
          a.value.at(-1).value,
          c(E)({
            p: e.value.style.dataLabel.prefix,
            v: a.value.at(-1).value,
            s: e.value.style.dataLabel.suffix,
            r: e.value.style.dataLabel.rounding
          }),
          { datapoint: a.value.at(-1) }
        )), 9, xe)) : v("", !0)
      ], 8, ie)) : (s(), C(oe, {
        key: 0,
        config: {
          type: "sparkline",
          style: {
            backgroundColor: e.value.style.backgroundColor,
            sparkline: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 12, re));
  }
}, Se = /* @__PURE__ */ ue(we, [["__scopeId", "data-v-541bb7c5"]]);
export {
  Se as default
};
