import { defineComponent as x, ref as s, watch as f, openBlock as E, createBlock as M, unref as i, normalizeStyle as j, onMounted as P, nextTick as _, onBeforeUnmount as T } from "vue";
import { cloneDeep as m, isEqual as v } from "lodash";
import $ from "vue-countup-v3";
import { Odometer as z } from "odometer_countup";
import { nanoid as h } from "nanoid";
import { autoInstallFont as A, jsonToCssStyle as B } from "../../utils/json2css.mjs";
const H = x({ name: "zv-text-over-number" }), K = /* @__PURE__ */ x({
  ...H,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  setup(y, { expose: w }) {
    const n = y, d = s(n.basicOption.countUp.startVal), U = (t) => {
      const a = s(h()), l = s(0), c = s(), r = s(), p = () => {
        window.SHJDatasourceV2({
          tId: n.uuid,
          sources: n.sources,
          callback: ({ data: e }) => {
            try {
              window.SHJParseEvent(n.useEvents, "dataListener", e), a.value = h(), l.value = Number(e[0].data[0].value), c.value = {
                startVal: d.value,
                separator: t.countUp.separator,
                decimal: t.countUp.decimal,
                decimalPlaces: t.countUp.decimalPlaces,
                duration: t.countUp.duration,
                prefix: t.countUp.prefix,
                suffix: t.countUp.suffix
              }, t.countUp.isOdometer && (c.value.plugin = new z({
                duration: t.countUp.duration,
                lastDigitDelay: 0
              })), d.value = l.value, t.isImitate ? b() : r.value && clearInterval(r.value);
            } catch {
              window.SHJParseEvent(n.useEvents, "dataListener", null);
            }
          }
        });
      }, F = (e) => {
        A(e.fontFamily);
        const o = {};
        e.color && e.color.includes("linear-gradient") && (o.backgroundImage = e.color, o["-webkit-background-clip"] = "text", o.color = "transparent");
        const C = {};
        return e.textAlign === "left" && (e.justifyContent = "flex-start"), e.textAlign === "center" && (e.justifyContent = "center"), e.textAlign === "right" && (e.justifyContent = "flex-end"), {
          ...B(e),
          ...o,
          ...C,
          ...e.textShadow.show ? { textShadow: `${e.textShadow.x}px ${e.textShadow.y}px ${e.textShadow.value}px ${e.textShadow.color}` } : {}
        };
      }, I = () => {
      }, b = () => {
        r.value && clearInterval(r.value);
        const e = t.countUp.isOdometer ? Math.floor(Math.random() * 6) + 5 : Math.floor(Math.random() * 4) + 3;
        r.value = setInterval(() => {
          d.value = l.value, c.value.startVal = d.value;
          const o = Number((Math.random() * 10).toFixed(t.countUp.decimalPlaces));
          o > 3 ? l.value += o : l.value -= o;
        }, e * 1e3);
      };
      return P(() => _(() => p())), T(() => {
        r.value && clearInterval(r.value);
      }), {
        key: a,
        init: p,
        options: c,
        endValue: l,
        onFinished: I,
        rendererDomStyle: F
      };
    }, {
      key: S,
      init: u,
      options: g,
      endValue: k,
      onFinished: D,
      rendererDomStyle: V
    } = U(n.basicOption);
    return f(() => m(n.basicOption), (t, a) => {
      v(t, a) || u();
    }, { deep: !0 }), f(() => m(n.sources), (t, a) => {
      v(t, a) || u();
    }, { deep: !0 }), w({
      refresh: () => u(),
      refreshView: () => u(),
      refreshData: () => u()
    }), (t, a) => (E(), M(i($), {
      key: i(S),
      class: "zerov-widget-over-number",
      "end-val": i(k),
      options: i(g),
      loop: t.basicOption.countUp.loop,
      delay: t.basicOption.countUp.delay,
      style: j(i(V)(t.basicOption.css)),
      onFinished: i(D)
    }, null, 8, ["end-val", "options", "loop", "delay", "style", "onFinished"]));
  }
});
export {
  K as default
};
