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