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