import { ref as g, shallowRef as O, onMounted as b, onBeforeUnmount as k } from "vue";
import { useResizeObserver as D } from "@vueuse/core";
import { debounce as M, cloneDeep as L, 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 "../../../text-text-basic/index.mjs";
import "../../../text-table-basic/index.mjs";
import "../../../chart-other-gauge/index.mjs";
import "../../../chart-other-gauge-stage/index.mjs";
import "../../../chart-other-gauge-grade/index.mjs";
import "../../../chart-other-word-cloud/index.mjs";
import "../../../chart-other-liquidfill/index.mjs";
import "../../../chart-other-funnel/index.mjs";
import "../../../chart-other-force/index.mjs";
import "../../../chart-other-radar/index.mjs";
import "../../../chart-other-funnel-split/index.mjs";
import "../../../chart-other-funnel-contrast/index.mjs";
import "../../../chart-other-candlestick-basic/index.mjs";
import "../../../chart-other-candlestick-shanghai/index.mjs";
import "../../../chart-other-candlestick-demo/index.mjs";
import "../../../chart-other-heatmap/index.mjs";
import "../../../chart-other-force2/index.mjs";
import "../../../chart-other-graph-basic/index.mjs";
import "../../../chart-other-graph-basic2/index.mjs";
import "../../../chart-other-graph-calendar/index.mjs";
import "../../../chart-other-tree-line/index.mjs";
import "../../../chart-other-treemap-basic/index.mjs";
import "../../../chart-other-sunburst-basic/index.mjs";
import "../../../chart-other-sunburst-basic2/index.mjs";
import "../../../chart-other-sunburst-basic3/index.mjs";
import "../../../chart-other-sunburst-basic4/index.mjs";
import "../../../chart-other-sunburst-book/index.mjs";
import "../../../chart-other-sunburst-radius/index.mjs";
import "../../../chart-other-sunburst-flavors/index.mjs";
import "../../../chart-other-parallel-basic/index.mjs";
import "../../../chart-other-parallel-mul/index.mjs";
import "../../../chart-other-circular-graph/index.mjs";
import "../../../map-earth-basic/index.mjs";
import "../../../map-earth-cool-tech/index.mjs";
import "../../../map-earth-particle/index.mjs";
import "../../../map-earth-hacker/index.mjs";
import "../../../map-earth-fly-line/index.mjs";
import "../../../chart-other-grid-percentage/index.mjs";
import "../../../chart-other-radar-stack/index.mjs";
import "../../../chart-other-funnel2/index.mjs";
import "../../../chart-other-label-gauge/index.mjs";
import "../../../chart-other-theme-river/index.mjs";
import "../../../chart-other-tree/index.mjs";
import "../../../chart-other-treemap/index.mjs";
import "../../../commons-product-model/index.mjs";
import "../../../commons-vr-photo/index.mjs";
import "../../../commons-vr-video/index.mjs";
import "../../../commons-three-loader/index.mjs";
import "../../../commons-three-loader3/index.mjs";
import "../../../commons-loop-iterator/index.mjs";
import "../../../commons-gaussian-splatting-view/index.mjs";
import "../../../commons-babylon/index.mjs";
import "../../../commons-svg/index.mjs";
import "../../../commons-weather/index.mjs";
import "../../../commons-weather-dynamic/index.mjs";
import "../../../media-wavesurfer/index.mjs";
import "../../../interaction-tabs/index.mjs";
import "../../../interaction-tabs2/index.mjs";
import "../../../interaction-button/index.mjs";
import "../../../interaction-button-image/index.mjs";
import "../../../interaction-select/index.mjs";
import "../../../interaction-input/index.mjs";
import "../../../interaction-radio/index.mjs";
import "../../../interaction-slider/index.mjs";
import "../../../interaction-switch/index.mjs";
import "../../../interaction-data-picker/index.mjs";
import "../../../interaction-button-refresh/index.mjs";
import "../../../media-image/index.mjs";
import "../../../text-title/index.mjs";
import "../../../commons-qrcode/index.mjs";
import "../../../media-video/index.mjs";
import "../../../media-audio/index.mjs";
import "../../../text-real-time/index.mjs";
import "../../../media-carousel/index.mjs";
import "../../../media-carousel-slides/index.mjs";
import "../../../media-iframe-carousel/index.mjs";
import "../../../media-iframe/index.mjs";
import "../../../media-m3u8/index.mjs";
import "../../../media-m3u8-dynamic/index.mjs";
import "../../../media-audio-dynamic/index.mjs";
import "../../../media-video-dynamic/index.mjs";
import "../../../media-image-dynamic/index.mjs";
import "../../../media-iframe-dynamic/index.mjs";
import "../../../media-flv/index.mjs";
import "../../../commons-echarts/index.mjs";
import "../../../text-over-number/index.mjs";
import "../../../text-table-scroll/index.mjs";
import "../../../text-carousel/index.mjs";
import "../../../text-row-scroll/index.mjs";
import "../../../text-text-dynamic/index.mjs";
import "../../../text-count-down/index.mjs";
import "../../../graphical-circle/index.mjs";
import "../../../graphical-diamond/index.mjs";
import "../../../graphical-hexagon/index.mjs";
import "../../../graphical-isosceles-triangle/index.mjs";
import "../../../graphical-pentagon/index.mjs";
import "../../../graphical-rect/index.mjs";
import "../../../graphical-right-triangle/index.mjs";
import "../../../scene-map3d/index.mjs";
import "../../../scene-amap2d/index.mjs";
import "../../../scene-amap3d/index.mjs";
import "../../../scene-vr/index.mjs";
import "../../../scene-unity-iframe/index.mjs";
import "../../../scene-unity-webgl/index.mjs";
import "../../../scene-ue-iframe/index.mjs";
import "../../../scene-ue-shj/index.mjs";
import "../../../scene-default/index.mjs";
import "../../../interaction/tabs/index.mjs";
import "../../../interaction/tabs-icon/index.mjs";
import "../../../interaction/button/index.mjs";
import "../../../interaction/date-picker/src/date-picker/index.mjs";
import "../../../interaction/date-picker/src/date-picker-range/index.mjs";
import "../../../text/list/index.mjs";
import "../../src/bar/basic/index.mjs";
import "../../src/bar/animation/index.mjs";
import "../../src/bar/contrast/index.mjs";
import "../../src/bar/contrast2/index.mjs";
import "../../src/bar/contrast3/index.mjs";
import "../../src/bar/gradient-column-chart/index.mjs";
import "../../src/bar/horizontal/index.mjs";
import "../../src/bar/horizontal-stack/index.mjs";
import "../../src/bar/line-bar/index.mjs";
import "../../src/bar/line-bar2/index.mjs";
import "../../src/bar/loop/index.mjs";
import "../../src/bar/mini/index.mjs";
import "../../src/bar/polar/index.mjs";
import "../../src/bar/polar-stack/index.mjs";
import "../../src/bar/polar2/index.mjs";
import "../../src/bar/radius-circle/index.mjs";
import "../../src/bar/rank/index.mjs";
import "../../src/bar/segmented-progress/index.mjs";
import "../../src/bar/spire/index.mjs";
import "../../src/bar/stack/index.mjs";
import "../../src/bar/stack-line/index.mjs";
import "../../src/bar/stack2/index.mjs";
import "../../src/bar/stack3/index.mjs";
import "../../src/bar/staggered/index.mjs";
import "../../src/bar/three/index.mjs";
import "../../src/bar/waterfall/index.mjs";
import "../../src/bar/zebra/index.mjs";
import "../../src/line/area-gradient/index.mjs";
import "../../src/line/area-highlight/index.mjs";
import "../../src/line/area-highlight2/index.mjs";
import "../../src/line/basic/index.mjs";
import "../../src/line/bump/index.mjs";
import "../../src/line/dashed/index.mjs";
import "../../src/line/ladder/index.mjs";
import "../../src/line/logarithm/index.mjs";
import "../../src/line/multix/index.mjs";
import "../../src/line/polar-double/index.mjs";
import "../../src/line/rain-flow/index.mjs";
import "../../src/line/scale/index.mjs";
import "../../src/line/smooth/index.mjs";
import "../../src/line/smooth-area/index.mjs";
import "../../src/line/stack/index.mjs";
import "../../src/line/stack-area/index.mjs";
import "../../src/line/temp/index.mjs";
import "../../src/line/vertical/index.mjs";
import "../../src/map/basic/index.mjs";
import "../../src/map/bmap-basic/index.mjs";
import "../../src/map/bmap-heatmap/index.mjs";
import "../../src/map/bmap-rich/index.mjs";
import "../../src/map/customize/index.mjs";
import "../../src/map/lines/index.mjs";
import "../../src/map/scatter/index.mjs";
import "../../src/pie/3d/index.mjs";
import "../../src/pie/basic/index.mjs";
import "../../src/pie/basic2/index.mjs";
import "../../src/pie/customized/index.mjs";
import "../../src/pie/index/index.mjs";
import "../../src/pie/interval/index.mjs";
import "../../src/pie/legend-scroll/index.mjs";
import "../../src/pie/radius/index.mjs";
import "../../src/pie/rose/index.mjs";
import "../../src/pie/round/index.mjs";
import "../../src/pie/sunburst/index.mjs";
import "../../src/scatter/basic/index.mjs";
import "../../src/scatter/basic2/index.mjs";
import "../../src/scatter/bubble/index.mjs";
import "../../src/scatter/ripples/index.mjs";
import "../../../hj-componets/zv-hj-tree-list/index.mjs";
import "../../../hj-componets/zv-hj-model-resource/index.mjs";
import "../../../hj-componets/zv-hj-one-map-config/index.mjs";
import "../../../hj-componets/zv-hj-video-control/index.mjs";
import "../../../hj-componets/zv-hj-video-page/index.mjs";
import "../../../hj-componets/zv-hj-password-input/index.mjs";
import "../../../hj-componets/zv-hj-carousel/index.mjs";
import "../../../hj-componets/zv-hj-video-monitor/index.mjs";
import "../../../hj-componets/zv-hj-scene-amap2d/index.mjs";
import "../../../hj-componets/zv-hj-scene-amap3d/index.mjs";
import "../../../hj-componets/zv-hj-person-face/index.mjs";
import "../../../hj-componets/zv-hj-resource-type-phone/index.mjs";
import "../../../hj-componets/zv-hj-tree-list-phone/index.mjs";
import "../../../hj-componets/zv-hj-video-page-phone/index.mjs";
import "../../../hj-componets/zv-hj-model-resource-phone/index.mjs";
import "../../../hj-componets/zv-hj-bottom-suspend/index.mjs";
import "../../../hj-componets/zv-hj-pagination/index.mjs";
import "../../../hj-componets/zv-hj-password-input-phone/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 Z } 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"
  );
}, Ti = ({ basicOption: p, useEvents: o, customRenderData: h, emits: m }) => {
  const e = x(), s = g(!0), i = O(null), w = 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)
          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;
    }
  }, y = M((u) => {
    s.value = !0, u = L(u), z(u).then(() => {
      B(u).then(() => {
        w(u);
      });
    }).catch((S) => {
    });
  }, 100);
  return b(() => {
    y(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: I,
    renderChart: y,
    renderData: w
  };
};
export {
  Ti as useChart
};
