import { defineComponent as d, watch as u, openBlock as v, createElementBlock as _, createElementVNode as w, unref as E } from "vue";
import { cloneDeep as s, isEqual as O } from "lodash";
import { useChart as x } from "../../core/useChart.mjs";
import { parseDataset as n } from "../../utils/parseDataset.mjs";
const g = { class: "zerov-widget" }, D = ["id"], k = d({ name: "zv-chart-pie-index" }), z = /* @__PURE__ */ d({
  ...k,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "chart-click",
    "chart-dblclick",
    "chart-mousedown",
    "chart-mouseover",
    "chart-mouseout",
    "chart-contextmenu"
  ],
  setup(l, { expose: p, emit: h }) {
    const e = l, m = h, {
      id: f,
      setOption: a,
      chart: b,
      renderChart: i,
      renderData: o
    } = x({
      basicOption: s(e.basicOption),
      useEvents: s(e.useEvents),
      customRenderData: (t) => {
        t = s(t);
        const r = s(e.basicOption.title.text);
        window.SHJDatasourceV2({
          tId: e.uuid,
          sources: e.sources,
          callback: ({ data: c }) => {
            try {
              window.SHJParseEvent(e.useEvents, "dataListener", c), t.dataset = n(s(c)), t.title.text = (n(s(c)).source[0][n(s(c)).dimensions[1]] || 0) + r, a(t);
            } catch {
              window.SHJParseEvent(e.useEvents, "dataListener", null), a(t);
            }
          }
        });
      },
      emit: m
    });
    return u(() => e.sources, () => {
      e.sources && e.sources.length > 0 && o(e.basicOption);
    }, {
      deep: !0
    }), u(() => s(e.basicOption), (t, r) => {
      O(t, r) || i(t);
    }, {
      deep: !0
    }), p({
      getEchartsInstance: () => b.value,
      refresh: () => {
        e.sources && e.sources.length > 0 && i(e.basicOption), o(e.basicOption);
      },
      refreshView: () => {
        e.sources && e.sources.length > 0 && i(e.basicOption);
      },
      refreshData: () => {
        o(e.basicOption);
      }
    }), (t, r) => (v(), _("div", g, [
      w("div", {
        id: E(f),
        class: "widget"
      }, null, 8, D)
    ]));
  }
});
export {
  z as default
};
