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