import { ref as v, shallowRef as O, onMounted as b, onBeforeUnmount as k } from "vue";
import { useResizeObserver as D } from "@vueuse/core";
import { debounce as M, cloneDeep as y, isArray as c } from "lodash";
import T from "is-electron";
import * as f from "echarts";
import { nanoid as x } from "nanoid";
import "echarts-wordcloud";
import "echarts-liquidfill";
import "../../components/text-text-basic/index.mjs";
import "../../components/text-table-basic/index.mjs";
import "../../components/chart-other-gauge/index.mjs";
import "../../components/chart-other-gauge-stage/index.mjs";
import "../../components/chart-other-gauge-grade/index.mjs";
import "../../components/chart-other-word-cloud/index.mjs";
import "../../components/chart-other-liquidfill/index.mjs";
import "../../components/chart-other-funnel/index.mjs";
import "../../components/chart-other-force/index.mjs";
import "../../components/chart-other-radar/index.mjs";
import "../../components/chart-other-funnel-split/index.mjs";
import "../../components/chart-other-funnel-contrast/index.mjs";
import "../../components/chart-other-candlestick-basic/index.mjs";
import "../../components/chart-other-candlestick-shanghai/index.mjs";
import "../../components/chart-other-candlestick-demo/index.mjs";
import "../../components/chart-other-heatmap/index.mjs";
import "../../components/chart-other-force2/index.mjs";
import "../../components/chart-other-graph-basic/index.mjs";
import "../../components/chart-other-graph-basic2/index.mjs";
import "../../components/chart-other-graph-calendar/index.mjs";
import "../../components/chart-other-tree-line/index.mjs";
import "../../components/chart-other-treemap-basic/index.mjs";
import "../../components/chart-other-sunburst-basic/index.mjs";
import "../../components/chart-other-sunburst-basic2/index.mjs";
import "../../components/chart-other-sunburst-basic3/index.mjs";
import "../../components/chart-other-sunburst-basic4/index.mjs";
import "../../components/chart-other-sunburst-book/index.mjs";
import "../../components/chart-other-sunburst-radius/index.mjs";
import "../../components/chart-other-sunburst-flavors/index.mjs";
import "../../components/chart-other-parallel-basic/index.mjs";
import "../../components/chart-other-parallel-mul/index.mjs";
import "../../components/chart-other-circular-graph/index.mjs";
import "../../components/map-earth-basic/index.mjs";
import "../../components/map-earth-cool-tech/index.mjs";
import "../../components/map-earth-particle/index.mjs";
import "../../components/map-earth-hacker/index.mjs";
import "../../components/map-earth-fly-line/index.mjs";
import "../../components/chart-other-grid-percentage/index.mjs";
import "../../components/chart-other-radar-stack/index.mjs";
import "../../components/chart-other-funnel2/index.mjs";
import "../../components/chart-other-label-gauge/index.mjs";
import "../../components/chart-other-theme-river/index.mjs";
import "../../components/chart-other-tree/index.mjs";
import "../../components/chart-other-treemap/index.mjs";
import "../../components/commons-product-model/index.mjs";
import "../../components/commons-vr-photo/index.mjs";
import "../../components/commons-vr-video/index.mjs";
import "../../components/commons-three-loader/index.mjs";
import "../../components/commons-three-loader3/index.mjs";
import "../../components/commons-loop-iterator/index.mjs";
import "../../components/commons-gaussian-splatting-view/index.mjs";
import "../../components/commons-babylon/index.mjs";
import "../../components/commons-svg/index.mjs";
import "../../components/commons-weather/index.mjs";
import "../../components/commons-weather-dynamic/index.mjs";
import "../../components/media-wavesurfer/index.mjs";
import "../../components/interaction-tabs/index.mjs";
import "../../components/interaction-tabs2/index.mjs";
import "../../components/interaction-button/index.mjs";
import "../../components/interaction-button-image/index.mjs";
import "../../components/interaction-select/index.mjs";
import "../../components/interaction-input/index.mjs";
import "../../components/interaction-radio/index.mjs";
import "../../components/interaction-slider/index.mjs";
import "../../components/interaction-switch/index.mjs";
import "../../components/interaction-data-picker/index.mjs";
import "../../components/interaction-button-refresh/index.mjs";
import "../../components/media-image/index.mjs";
import "../../components/text-title/index.mjs";
import "../../components/commons-qrcode/index.mjs";
import "../../components/media-video/index.mjs";
import "../../components/media-audio/index.mjs";
import "../../components/text-real-time/index.mjs";
import "../../components/media-carousel/index.mjs";
import "../../components/media-carousel-slides/index.mjs";
import "../../components/media-iframe-carousel/index.mjs";
import "../../components/media-iframe/index.mjs";
import "../../components/media-m3u8/index.mjs";
import "../../components/media-m3u8-dynamic/index.mjs";
import "../../components/media-audio-dynamic/index.mjs";
import "../../components/media-video-dynamic/index.mjs";
import "../../components/media-image-dynamic/index.mjs";
import "../../components/media-iframe-dynamic/index.mjs";
import "../../components/media-flv/index.mjs";
import "../../components/commons-echarts/index.mjs";
import "../../components/text-over-number/index.mjs";
import "../../components/text-table-scroll/index.mjs";
import "../../components/text-carousel/index.mjs";
import "../../components/text-row-scroll/index.mjs";
import "../../components/text-text-dynamic/index.mjs";
import "../../components/text-count-down/index.mjs";
import "../../components/graphical-circle/index.mjs";
import "../../components/graphical-diamond/index.mjs";
import "../../components/graphical-hexagon/index.mjs";
import "../../components/graphical-isosceles-triangle/index.mjs";
import "../../components/graphical-pentagon/index.mjs";
import "../../components/graphical-rect/index.mjs";
import "../../components/graphical-right-triangle/index.mjs";
import "../../components/scene-map3d/index.mjs";
import "../../components/scene-amap2d/index.mjs";
import "../../components/scene-amap3d/index.mjs";
import "../../components/scene-vr/index.mjs";
import "../../components/scene-unity-iframe/index.mjs";
import "../../components/scene-unity-webgl/index.mjs";
import "../../components/scene-ue-iframe/index.mjs";
import "../../components/scene-ue-shj/index.mjs";
import "../../components/scene-default/index.mjs";
import "../../components/interaction/tabs/index.mjs";
import "../../components/interaction/tabs-icon/index.mjs";
import "../../components/interaction/button/index.mjs";
import "../../components/interaction/date-picker/src/date-picker/index.mjs";
import "../../components/interaction/date-picker/src/date-picker-range/index.mjs";
import "../../components/text/list/index.mjs";
import "../../components/chart/src/bar/basic/index.mjs";
import "../../components/chart/src/bar/animation/index.mjs";
import "../../components/chart/src/bar/contrast/index.mjs";
import "../../components/chart/src/bar/contrast2/index.mjs";
import "../../components/chart/src/bar/contrast3/index.mjs";
import "../../components/chart/src/bar/gradient-column-chart/index.mjs";
import "../../components/chart/src/bar/horizontal/index.mjs";
import "../../components/chart/src/bar/horizontal-stack/index.mjs";
import "../../components/chart/src/bar/line-bar/index.mjs";
import "../../components/chart/src/bar/line-bar2/index.mjs";
import "../../components/chart/src/bar/loop/index.mjs";
import "../../components/chart/src/bar/mini/index.mjs";
import "../../components/chart/src/bar/polar/index.mjs";
import "../../components/chart/src/bar/polar-stack/index.mjs";
import "../../components/chart/src/bar/polar2/index.mjs";
import "../../components/chart/src/bar/radius-circle/index.mjs";
import "../../components/chart/src/bar/rank/index.mjs";
import "../../components/chart/src/bar/segmented-progress/index.mjs";
import "../../components/chart/src/bar/spire/index.mjs";
import "../../components/chart/src/bar/stack/index.mjs";
import "../../components/chart/src/bar/stack-line/index.mjs";
import "../../components/chart/src/bar/stack2/index.mjs";
import "../../components/chart/src/bar/stack3/index.mjs";
import "../../components/chart/src/bar/staggered/index.mjs";
import "../../components/chart/src/bar/three/index.mjs";
import "../../components/chart/src/bar/waterfall/index.mjs";
import "../../components/chart/src/bar/zebra/index.mjs";
import "../../components/chart/src/line/area-gradient/index.mjs";
import "../../components/chart/src/line/area-highlight/index.mjs";
import "../../components/chart/src/line/area-highlight2/index.mjs";
import "../../components/chart/src/line/basic/index.mjs";
import "../../components/chart/src/line/bump/index.mjs";
import "../../components/chart/src/line/dashed/index.mjs";
import "../../components/chart/src/line/ladder/index.mjs";
import "../../components/chart/src/line/logarithm/index.mjs";
import "../../components/chart/src/line/multix/index.mjs";
import "../../components/chart/src/line/polar-double/index.mjs";
import "../../components/chart/src/line/rain-flow/index.mjs";
import "../../components/chart/src/line/scale/index.mjs";
import "../../components/chart/src/line/smooth/index.mjs";
import "../../components/chart/src/line/smooth-area/index.mjs";
import "../../components/chart/src/line/stack/index.mjs";
import "../../components/chart/src/line/stack-area/index.mjs";
import "../../components/chart/src/line/temp/index.mjs";
import "../../components/chart/src/line/vertical/index.mjs";
import "../../components/chart/src/map/basic/index.mjs";
import "../../components/chart/src/map/bmap-basic/index.mjs";
import "../../components/chart/src/map/bmap-heatmap/index.mjs";
import "../../components/chart/src/map/bmap-rich/index.mjs";
import "../../components/chart/src/map/customize/index.mjs";
import "../../components/chart/src/map/lines/index.mjs";
import "../../components/chart/src/map/scatter/index.mjs";
import "../../components/chart/src/pie/3d/index.mjs";
import "../../components/chart/src/pie/basic/index.mjs";
import "../../components/chart/src/pie/basic2/index.mjs";
import "../../components/chart/src/pie/customized/index.mjs";
import "../../components/chart/src/pie/index/index.mjs";
import "../../components/chart/src/pie/interval/index.mjs";
import "../../components/chart/src/pie/legend-scroll/index.mjs";
import "../../components/chart/src/pie/radius/index.mjs";
import "../../components/chart/src/pie/rose/index.mjs";
import "../../components/chart/src/pie/round/index.mjs";
import "../../components/chart/src/pie/sunburst/index.mjs";
import "../../components/chart/src/scatter/basic/index.mjs";
import "../../components/chart/src/scatter/basic2/index.mjs";
import "../../components/chart/src/scatter/bubble/index.mjs";
import "../../components/chart/src/scatter/ripples/index.mjs";
/* empty css             */
/* empty css                    */
import "../../plugins/datasource/utils/request.mjs";
import "../../plugins/datasource/utils/wsManager.mjs";
import { SHJParseEvent as n } from "../../plugins/event/index.mjs";
import { HoverLoop as L } from "../utils/hoverLoop.mjs";
const z = (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")
      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);
      }
    else
      return fetch((T() ? "gismap/" : "/gismap/") + m + ".json").then((e) => e.json()).then((e) => {
        f.registerMap(m, e);
      }).catch((e) => {
      });
  });
  return Promise.all(h);
}, B = async (p) => {
  p.bmap && await import(
    /* @vite-ignore */
    "echarts/extension/bmap/bmap"
  );
}, si = ({ basicOption: p, useEvents: o, customRenderData: h, emit: m }) => {
  const e = x(), s = v(!0), i = O(null), d = h, a = v(null), l = v(null), S = (u, w) => {
    try {
      i.value || (i.value = f.init(document.getElementById(e), null, { renderer: w || "svg" }));
      const t = y(u);
      if (t) {
        if (i.value.setOption(t, !0), t.hoverLoop)
          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 Z = t.dataZoom[0].endValue, I = t.dataZoom[0].startValue, V = () => {
              l.value = setInterval(() => {
                t.dataZoom[0].endValue > r - 2 ? (t.dataZoom[0].endValue = Z, t.dataZoom[0].startValue = I) : (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 L(i.value, t);
          }), a.value = new L(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;
    }
  }, g = M((u) => {
    s.value = !0, u = y(u), z(u).then(() => {
      B(u).then(() => {
        d(u);
      });
    }).catch((w) => {
    });
  }, 100);
  return b(() => {
    g(p), D(document.getElementById(e), (u) => {
      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: S,
    renderChart: g,
    renderData: d
  };
};
export {
  si as useChart
};
