import { defineComponent as f, watch as u, createElementBlock as x, openBlock as _, createElementVNode as O, unref as y } from "vue";
import { cloneDeep as c, isEqual as g } from "lodash";
import { SHJDatasourceV2 as D } from "../../commons/plugins/datasource/index.mjs";
import { useChart as k } from "../../commons/core/useChart.mjs";
import { parseDataset as w } from "../../commons/utils/parseDataset.mjs";
import { SHJParseEvent as l } from "../../commons/plugins/event/index.mjs";
const A = { class: "zerov-widget" }, L = ["id"], C = f({ name: "zv-chart-bar-contrast" }), S = /* @__PURE__ */ f({
  ...C,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "chart-click",
    "chart-dblclick",
    "chart-mousedown",
    "chart-mouseover",
    "chart-mouseout",
    "chart-contextmenu"
  ],
  setup(m, { expose: p, emit: h }) {
    const e = m, v = h, {
      id: d,
      setOption: n,
      chart: b,
      renderChart: a,
      renderData: o
    } = k({
      basicOption: c(e.basicOption),
      useEvents: c(e.useEvents),
      customRenderData: (r) => {
        r = c(r), D.parse({
          tId: e.uuid,
          sources: e.sources,
          callback: ({ data: t }) => {
            try {
              l.parseEvents(e.useEvents, "dataListener", t), r.dataset = w(c(t)), E(r), n(r);
            } catch {
              l.parseEvents(e.useEvents, "dataListener", null), n(r);
            }
          }
        });
      },
      emit: v
    }), E = (r) => {
      try {
        r.series.forEach((t) => {
          t.label.formatter = (s) => {
            for (const i in s.value)
              if (typeof s.value[i] == "number" && s.value[i] < 0)
                return -s.value[i];
          };
        }), r.xAxis[0].type === "value" && r.xAxis.forEach((t) => {
          t.axisLabel.formatter = (s) => s < 0 ? -s : s;
        }), r.yAxis[0].type === "value" && r.yAxis.forEach((t) => {
          t.axisLabel.formatter = (s) => s < 0 ? -s : s;
        });
      } catch {
      }
    };
    return u(() => e.sources, () => {
      e.sources && e.sources.length > 0 && o(e.basicOption);
    }, {
      deep: !0
    }), u(() => c(e.basicOption), (r, t) => {
      g(r, t) || a(r);
    }, {
      deep: !0
    }), p({
      getEchartsInstance: () => b.value,
      refresh: () => {
        e.sources && e.sources.length > 0 && a(e.basicOption), o(e.basicOption);
      },
      refreshView: () => {
        e.sources && e.sources.length > 0 && a(e.basicOption);
      },
      refreshData: () => {
        o(e.basicOption);
      }
    }), (r, t) => (_(), x("div", A, [
      O("div", {
        id: y(d),
        class: "widget"
      }, null, 8, L)
    ]));
  }
});
export {
  S as default
};
