import { ref as g, shallowRef as O, onMounted as b, onBeforeUnmount as k } from "vue";
import { useResizeObserver as D } from "@vueuse/core";
import { cloneDeep as L, isArray as c } from "lodash";
import M from "is-electron";
import * as f from "echarts";
import { nanoid as T } from "nanoid";
import "echarts-wordcloud";
import "echarts-liquidfill";
/* empty css                          */
/* empty css                          */
import "../../../../components/Interaction/components/Tabs/index.mjs";
import "../../../../components/Interaction/components/Tabs-icon/index.mjs";
import "../../../../components/Interaction/components/Button/index.mjs";
import "../../../../components/Interaction/components/DatePicker/index.mjs";
import "../../../../components/Interaction/components/DatePickerRange/index.mjs";
import "../../../../components/Interaction/components/Switch/index.mjs";
import "../../../../components/Interaction/components/Input/index.mjs";
import "../../../../components/Interaction/components/Select/index.mjs";
import "../../../../components/Interaction/components/Slider/index.mjs";
import "../../../../components/Text/components/List/index.mjs";
import "../../../../components/Text/components/Text/index.mjs";
import "../../../../components/Text/components/TextDynamic/index.mjs";
import "../../../../components/Text/components/TableBasic/index.mjs";
import "../../../../components/Text/components/TableScroll/index.mjs";
import "../../../../components/Text/components/RowScroll/index.mjs";
import "../../../../components/Text/components/RealTime/index.mjs";
import "../../../../components/Text/components/OverNumber/index.mjs";
import "../../../../components/Text/components/CountDown/index.mjs";
import "../../../../components/Text/components/TextCarousel/index.mjs";
import "../../../../components/Media/components/Audio/index.mjs";
import "../../../../components/Media/components/Video/index.mjs";
import "../../../../components/Media/components/Carousel/index.mjs";
import "../../../../components/Media/components/Flv/index.mjs";
import "../../../../components/Media/components/Iframe/index.mjs";
import "../../../../components/Media/components/IframeCarousel/index.mjs";
import "../../../../components/Media/components/Image/index.mjs";
import "../../../../components/Media/components/ImageDynamic/index.mjs";
import "../../../../components/Media/components/M3u8/index.mjs";
import "../../../../components/Media/components/Wavesurfer/index.mjs";
import "../../../../components/Media/components/Weather/index.mjs";
import "../../../../components/Media/components/Qrcode/index.mjs";
import "../../../../components/Chart/components/bar/basic/index.mjs";
import "../../../../components/Chart/components/bar/animation/index.mjs";
import "../../../../components/Chart/components/bar/contrast/index.mjs";
import "../../../../components/Chart/components/bar/contrast2/index.mjs";
import "../../../../components/Chart/components/bar/contrast3/index.mjs";
import "../../../../components/Chart/components/bar/gradient-column-chart/index.mjs";
import "../../../../components/Chart/components/bar/horizontal/index.mjs";
import "../../../../components/Chart/components/bar/horizontal-stack/index.mjs";
import "../../../../components/Chart/components/bar/line-bar/index.mjs";
import "../../../../components/Chart/components/bar/line-bar2/index.mjs";
import "../../../../components/Chart/components/bar/loop/index.mjs";
import "../../../../components/Chart/components/bar/mini/index.mjs";
import "../../../../components/Chart/components/bar/polar/index.mjs";
import "../../../../components/Chart/components/bar/polar-stack/index.mjs";
import "../../../../components/Chart/components/bar/polar2/index.mjs";
import "../../../../components/Chart/components/bar/radius-circle/index.mjs";
import "../../../../components/Chart/components/bar/rank/index.mjs";
import "../../../../components/Chart/components/bar/segmented-progress/index.mjs";
import "../../../../components/Chart/components/bar/spire/index.mjs";
import "../../../../components/Chart/components/bar/stack/index.mjs";
import "../../../../components/Chart/components/bar/stack-line/index.mjs";
import "../../../../components/Chart/components/bar/stack2/index.mjs";
import "../../../../components/Chart/components/bar/stack3/index.mjs";
import "../../../../components/Chart/components/bar/staggered/index.mjs";
import "../../../../components/Chart/components/bar/three/index.mjs";
import "../../../../components/Chart/components/bar/waterfall/index.mjs";
import "../../../../components/Chart/components/bar/zebra/index.mjs";
import "../../../../components/Chart/components/line/area-gradient/index.mjs";
import "../../../../components/Chart/components/line/area-highlight/index.mjs";
import "../../../../components/Chart/components/line/area-highlight2/index.mjs";
import "../../../../components/Chart/components/line/basic/index.mjs";
import "../../../../components/Chart/components/line/bump/index.mjs";
import "../../../../components/Chart/components/line/dashed/index.mjs";
import "../../../../components/Chart/components/line/ladder/index.mjs";
import "../../../../components/Chart/components/line/logarithm/index.mjs";
import "../../../../components/Chart/components/line/multix/index.mjs";
import "../../../../components/Chart/components/line/polar-double/index.mjs";
import "../../../../components/Chart/components/line/rain-flow/index.mjs";
import "../../../../components/Chart/components/line/scale/index.mjs";
import "../../../../components/Chart/components/line/smooth/index.mjs";
import "../../../../components/Chart/components/line/smooth-area/index.mjs";
import "../../../../components/Chart/components/line/stack/index.mjs";
import "../../../../components/Chart/components/line/stack-area/index.mjs";
import "../../../../components/Chart/components/line/temp/index.mjs";
import "../../../../components/Chart/components/line/vertical/index.mjs";
import "../../../../components/Chart/components/map/basic/index.mjs";
import "../../../../components/Chart/components/map/bmap-basic/index.mjs";
import "../../../../components/Chart/components/map/bmap-heatmap/index.mjs";
import "../../../../components/Chart/components/map/bmap-rich/index.mjs";
import "../../../../components/Chart/components/map/customize/index.mjs";
import "../../../../components/Chart/components/map/lines/index.mjs";
import "../../../../components/Chart/components/map/scatter/index.mjs";
import "../../../../components/Chart/components/pie/3d/index.mjs";
import "../../../../components/Chart/components/pie/basic/index.mjs";
import "../../../../components/Chart/components/pie/basic2/index.mjs";
import "../../../../components/Chart/components/pie/customized/index.mjs";
import "../../../../components/Chart/components/pie/index/index.mjs";
import "../../../../components/Chart/components/pie/interval/index.mjs";
import "../../../../components/Chart/components/pie/legend-scroll/index.mjs";
import "../../../../components/Chart/components/pie/radius/index.mjs";
import "../../../../components/Chart/components/pie/rose/index.mjs";
import "../../../../components/Chart/components/pie/round/index.mjs";
import "../../../../components/Chart/components/pie/sunburst/index.mjs";
import "../../../../components/Chart/components/scatter/basic/index.mjs";
import "../../../../components/Chart/components/scatter/basic2/index.mjs";
import "../../../../components/Chart/components/scatter/bubble/index.mjs";
import "../../../../components/Chart/components/scatter/ripples/index.mjs";
import "../../../../components/Chart/components/other/candlestick-basic/index.mjs";
import "../../../../components/Chart/components/other/sunburst-basic/index.mjs";
import "../../../../components/Chart/components/other/sunburst-basic2/index.mjs";
import "../../../../components/Chart/components/other/sunburst-basic3/index.mjs";
import "../../../../components/Chart/components/other/sunburst-basic4/index.mjs";
import "../../../../components/Chart/components/other/sunburst-book/index.mjs";
import "../../../../components/Chart/components/other/sunburst-flavors/index.mjs";
import "../../../../components/Chart/components/other/sunburst-radius/index.mjs";
import "../../../../components/Chart/components/other/funnel/index.mjs";
import "../../../../components/Chart/components/other/funnel-contrast/index.mjs";
import "../../../../components/Chart/components/other/funnel-split/index.mjs";
import "../../../../components/Chart/components/other/funnel2/index.mjs";
import "../../../../components/Chart/components/other/force/index.mjs";
import "../../../../components/Chart/components/other/force2/index.mjs";
import "../../../../components/Chart/components/other/gauge/index.mjs";
import "../../../../components/Chart/components/other/gauge-grade/index.mjs";
import "../../../../components/Chart/components/other/gauge-stage/index.mjs";
import "../../../../components/Chart/components/other/graph-basic/index.mjs";
import "../../../../components/Chart/components/other/graph-basic2/index.mjs";
import "../../../../components/Chart/components/other/graph-calendar/index.mjs";
import "../../../../components/Chart/components/other/circular-graph/index.mjs";
import "../../../../components/Chart/components/other/heatmap/index.mjs";
import "../../../../components/Chart/components/other/liquidfill/index.mjs";
import "../../../../components/Chart/components/other/parallel-basic/index.mjs";
import "../../../../components/Chart/components/other/parallel-mul/index.mjs";
import "../../../../components/Chart/components/other/radar-stack/index.mjs";
import "../../../../components/Chart/components/other/tree/index.mjs";
import "../../../../components/Chart/components/other/tree-line/index.mjs";
import "../../../../components/Chart/components/other/word-cloud/index.mjs";
import "../../../../components/Chart/components/other/treemap/index.mjs";
import "../../../../components/Chart/components/other/treemap-basic/index.mjs";
import "../../../../components/Chart/components/other/label-gauge/index.mjs";
import "../../../../components/Chart/components/other/grid-percentage/index.mjs";
import "../../../../components/Chart/components/other/radar/index.mjs";
import "../../../../components/Commons/components/CustomComponentRender/index.mjs";
import "../../../../components/Commons/components/Graphical/index.mjs";
import "../../../../components/Commons/components/Svg/index.mjs";
import "../../../../components/Commons/components/ModelViewer/index.mjs";
import "../../../../components/Commons/components/VrVideo/index.mjs";
import "../../../../components/Commons/components/VrPhoto/index.mjs";
import "../../../../components/Commons/components/Babylon/index.mjs";
import "../../../../components/Commons/components/Echarts/index.mjs";
import "../../../../components/Commons/components/GSViewer/index.mjs";
import "../../../../components/Scene/components/Amap2d/index.mjs";
import "../../../../components/Scene/components/Amap3d/index.mjs";
import "../../../../components/Scene/components/Default/index.mjs";
import "../../../../components/Scene/components/Map2d/index.mjs";
import "../../../../components/Scene/components/Map3d/index.mjs";
import "../../../../components/Scene/components/UeIframe/index.mjs";
import "../../../../components/Scene/components/UeShj/index.mjs";
import "../../../../components/Scene/components/UnityIframe/index.mjs";
import "../../../../components/Scene/components/UnityWebgl/index.mjs";
import "../../../../components/Scene/components/Vr/index.mjs";
import "../../../../components/Scene/components/Earth/index.mjs";
import { SHJParseEvent as n } from "../../../plugins/event/index.mjs";
import "../../../plugins/datasource/utils/request.mjs";
import "mqtt";
import { HoverLoop as Z } from "../utils/hoverLoop.mjs";
const x = (p) => {
  const o = [];
  p.geo && (c(p.geo) ? o.push(...p.geo.map((m) => m.map)) : o.push(p.geo.map)), p.series && c(p.series) && p.series.forEach((m) => {
    m.map && o.push(m.map);
  });
  const h = o.map((m) => {
    if (m === "customize")
      try {
        if (c(p.geo)) {
          const e = JSON.parse(
            p.geo.find((s) => s.map === "customize").geoData
          );
          return f.registerMap(m, e);
        } else {
          const e = JSON.parse(p.geo.geoData);
          return f.registerMap(m, e);
        }
      } catch {
        return null;
      }
    else
      return fetch((M() ? "gismap/" : "/gismap/") + m + ".json").then((e) => e.json()).then((e) => {
        f.registerMap(m, e);
      }).catch((e) => {
      });
  });
  return Promise.all(h);
}, z = async (p) => {
  p.bmap && await import(
    /* @vite-ignore */
    "echarts/extension/bmap/bmap"
  );
}, Hr = ({
  basicOption: p,
  useEvents: o,
  customRenderData: h,
  emits: m
}) => {
  const e = T(), s = g(!0), i = O(null), y = h, a = g(null), l = g(null), I = (u, S) => {
    try {
      i.value || (i.value = f.init(document.getElementById(e), null, {
        renderer: S || "svg"
      }));
      const t = L(u);
      if (t) {
        if (t.tooltip && t.tooltip.isFormatter) {
          let r = `
                    ${t.tooltip.formatterCode}

                    // 在这里调用 filter 函数，并传递 data 参数
                    return custom(params);
                `;
          r = r.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, ""), t.tooltip.formatter = (v) => {
            try {
              return new Function("params", r)(v);
            } catch {
              return "";
            }
          };
        }
        if (i.value.setOption(t, !0), t.hoverLoop && t.hoverLoop.enable)
          if (l.value && clearInterval(l.value), a.value && a.value.closeSwitchTooltip(), t.hoverLoop.type === "方式二") {
            let r = 0;
            t.dataset && t.dataset.source && (r = t.dataset.source.length), t.series[0] && t.series[0].data && (r = t.series[0].data.length);
            const v = t.dataZoom[0].endValue, d = t.dataZoom[0].startValue, V = () => {
              l.value = setInterval(() => {
                t.dataZoom[0].endValue > r - 2 ? (t.dataZoom[0].endValue = v, t.dataZoom[0].startValue = d) : (t.dataZoom[0].endValue = t.dataZoom[0].endValue + 1, t.dataZoom[0].startValue = t.dataZoom[0].startValue + 1), i.value.setOption(t);
              }, t.hoverLoop.delay2);
            };
            i.value.on("mousemove", function() {
              l.value && clearInterval(l.value);
            }), i.value.on("mouseout", function() {
              l.value && clearInterval(l.value), V();
            }), V();
          } else t.hoverLoop.type === "方式一" && (i.value.on("mousemove", function() {
            a.value && a.value.closeSwitchTooltip();
          }), i.value.on("mouseout", function() {
            a.value && a.value.closeSwitchTooltip(), a.value = new Z(i.value, t);
          }), a.value = new Z(i.value, t));
        else
          l.value && clearInterval(l.value), a.value && a.value.closeSwitchTooltip();
        i.value.on("click", (r) => {
          o && c(o) && o.length > 0 && (m("chart-click", r), n.parseEvents(o, "chart-click", r));
        }), i.value.on("dblclick", (r) => {
          o && c(o) && o.length > 0 && (m("chart-dblclick", r), n.parseEvents(o, "chart-dblclick", r));
        }), i.value.on("mousedown", (r) => {
          o && c(o) && o.length > 0 && (m("chart-mousedown", r), n.parseEvents(o, "chart-mousedown", r));
        }), i.value.on("mouseup", (r) => {
          o && c(o) && o.length > 0 && (m("chart-mouseup", r), n.parseEvents(o, "chart-mouseup", r));
        }), i.value.on("mouseover", (r) => {
          o && c(o) && o.length > 0 && (m("chart-mouseover", r), n.parseEvents(o, "chart-mouseover", r));
        }), i.value.on("mouseout", (r) => {
          o && c(o) && o.length > 0 && (m("chart-mouseout", r), n.parseEvents(o, "chart-mouseout", r));
        }), i.value.on("contextmenu", (r) => {
          o && c(o) && o.length > 0 && (m("chart-contextmenu", r), n.parseEvents(o, "chart-contextmenu", r));
        }), s.value = !1;
      }
    } catch {
      try {
        i.value.dispose();
      } catch {
      }
      i.value = null;
    }
  }, w = (u) => {
    s.value = !0, u = L(u), x(u).then(() => {
      z(u).then(() => {
        y(u);
      });
    }).catch((S) => {
    });
  };
  return b(() => {
    w(p), D(document.getElementById(e), () => {
      i.value && i.value.resize();
    });
  }), k(() => {
    a.value && a.value.closeSwitchTooltip(), l.value && clearInterval(l.value);
    try {
      i.value && i.value.dispose();
    } catch {
    }
  }), {
    id: e,
    status: s,
    chart: i,
    setOption: I,
    renderChart: w,
    renderData: y
  };
};
export {
  Hr as useChart
};
