import { defineComponent as g, toRefs as h, computed as B, ref as C, onMounted as z, onUnmounted as _, watch as u, openBlock as k, createElementBlock as b, normalizeStyle as T, unref as E } from "vue";
import { initChart as I, destroyChart as M, updatedChartOption as f, tooltipAnimationFunc as S } from "./echartsFunc.mjs";
import { debounce as d } from "lodash";
const R = /* @__PURE__ */ g({
  name: "EchartsContainer",
  props: {
    style: { default: () => ({
      width: 300,
      height: 300
    }) },
    options: null,
    tooltipAnimation: { type: Boolean, default: !1 },
    theme: null
  },
  setup(v) {
    const o = v, { options: y, style: n, tooltipAnimation: x } = h(o), w = B(() => {
      let e = typeof n.value.width == "number" ? n.value.width + "px" : n.value.width, r = typeof n.value.height == "number" ? n.value.height + "px" : n.value.height;
      return {
        width: e,
        height: r
      };
    });
    let a = C(), t;
    z(() => {
      l && clearTimeout(l), a.value && (t = I(a.value, y.value), t.on("click", function(e) {
        console.log(e);
      }), t.on("mouseover", (e) => {
        s = !1;
      }), t.on("mouseout", (e) => {
        s = !0;
      }), x.value && (console.log("onMounted\u7684\u72B6\u6001"), p()), window.onresize = d(() => {
        t.resize();
      }));
    }), _(() => {
      M(t), a.value = null, window.onresize = null, l && clearTimeout(l);
    }), u(
      () => o.options,
      (e) => {
        f(t, e);
      },
      {
        deep: !0
      }
    ), u(
      () => o.tooltipAnimation,
      () => {
        p();
      }
    ), u(
      () => o.style,
      () => {
        d(() => {
          t.resize();
        })();
      }
    ), u(
      () => o.theme,
      (e) => {
        f(t, e);
      }
    );
    let i = 0, m = 0, s = !0, l;
    const p = () => {
      const { options: e, tooltipAnimation: r } = h(o);
      if (r && s) {
        if (S(t, i, m), m = i, i++, e.value) {
          const A = e.value.series[0].type;
          let c;
          A == "pie" ? c = e.value.series[0].data.length : c = e.value.xAxis.data.length, i >= c && (i = 0);
        }
        l = setTimeout(() => {
          p();
        }, 1e3 * 2);
      }
    };
    return (e, r) => (k(), b("div", {
      ref_key: "chartBox",
      ref: a,
      class: "echartsBox",
      style: T({ ...E(w) })
    }, null, 4));
  }
});
export {
  R as default
};
