import { defineComponent as p, watch as m, createElementBlock as x, openBlock as g, createElementVNode as k, unref as D } from "vue";
import { cloneDeep as o, isEqual as y } from "lodash";
import { SHJDatasourceV2 as S } from "../../commons/core/datasource/index.mjs";
import { useChart as V } from "../../commons/core/useChart.mjs";
import { parseDataset as f } from "../../commons/utils/parseDataset.mjs";
import { cloneSeries as C } from "../../commons/utils/cloneSeries.mjs";
const H = { class: "zerov-widget" }, J = ["id"], N = p({ name: "zv-chart-other-radar" }), j = /* @__PURE__ */ p({
  ...N,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "chart-click",
    "chart-dblclick",
    "chart-mousedown",
    "chart-mouseover",
    "chart-mouseout",
    "chart-contextmenu"
  ],
  setup(b, { expose: E, emit: O }) {
    const e = b, _ = O, {
      id: v,
      setOption: h,
      chart: w,
      renderChart: n,
      renderData: i
    } = V({
      basicOption: o(e.basicOption),
      useEvents: o(e.useEvents),
      customRenderData: (s) => {
        s = o(s), S.parse({
          tId: e.uuid,
          sources: e.sources,
          callback: ({ data: c }) => {
            try {
              let u = function(r) {
                return r.reduce((t, a) => t.includes(a) ? t : [...t, a], []);
              };
              window.SHJParseEvent(e.useEvents, "dataListener", c), s.dataset = f(o(c)), s.series = C(c, s.series);
              const d = [], l = [];
              s.dataset.source.forEach((r) => {
                for (const t in r)
                  if (Object.prototype.hasOwnProperty.call(r, t)) {
                    const a = r[t];
                    Number(a) && (l.push(Number(a)), d.push(t));
                  }
              }), s.radar.indicator = [], u(d).forEach((r) => {
                s.radar.indicator.push(
                  {
                    text: r,
                    max: 2e3
                  }
                );
              }), s.radar.indicator.forEach((r) => {
                r.max = l.sort((t, a) => a - t)[0];
              }), s.dataset = f(o(c), u(d)), h(s);
            } catch {
              window.SHJParseEvent(e.useEvents, "dataListener", null), h(s);
            }
          }
        });
      },
      emit: _
    });
    return m(() => e.sources, () => {
      e.sources && e.sources.length > 0 && i(e.basicOption);
    }, {
      deep: !0
    }), m(() => o(e.basicOption), (s, c) => {
      y(s, c) || n(s);
    }, {
      deep: !0
    }), E({
      getEchartsInstance: () => w.value,
      refresh: () => {
        e.sources && e.sources.length > 0 && n(e.basicOption), i(e.basicOption);
      },
      refreshView: () => {
        e.sources && e.sources.length > 0 && n(e.basicOption);
      },
      refreshData: () => {
        i(e.basicOption);
      }
    }), (s, c) => (g(), x("div", H, [
      k("div", {
        id: D(v),
        class: "widget"
      }, null, 8, J)
    ]));
  }
});
export {
  j as default
};
