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