import { jsx as n } from "react/jsx-runtime";
import { useState as f, useRef as b, useEffect as w } from "react";
import { E as x, r as C } from "./index-BucR6RTl.mjs";
import { g as d, a as M } from "./mapData-Cg2oKcpf.mjs";
function I({ mapRegion: t = "china", mapData: h, chartTitle: i }) {
  const [p, r] = f(!0), [c, o] = f(null), [y, a] = f(!1), u = b(/* @__PURE__ */ new Set());
  w(() => {
    let e = !1;
    return (async () => {
      if (r(!0), o(null), a(!1), !d(t)) {
        o("未找到地图区域配置"), r(!1);
        return;
      }
      if (u.current.has(t)) {
        a(!0), r(!1);
        return;
      }
      try {
        const l = M(t), s = await fetch(l);
        if (!s.ok)
          throw new Error(`加载失败: ${s.status}`);
        const g = await s.json();
        if (e) return;
        C(t, g), u.current.add(t), a(!0), r(!1);
      } catch (l) {
        if (e) return;
        console.error("地图加载失败:", l), o("地图数据加载失败"), r(!1);
      }
    })(), () => {
      e = !0;
    };
  }, [t]);
  const m = () => {
    const e = d(t);
    return {
      backgroundColor: "transparent",
      title: i ? {
        text: i,
        left: "center",
        textStyle: { color: "#fff", fontSize: 16 }
      } : void 0,
      tooltip: {
        trigger: "item",
        formatter: "{b}: {c}"
      },
      visualMap: {
        min: 0,
        max: 100,
        left: "left",
        top: "bottom",
        text: ["高", "低"],
        calculable: !0,
        inRange: {
          color: ["#50a3ba", "#eac736", "#d94e5d"]
        },
        textStyle: { color: "#fff" }
      },
      series: [{
        name: (e == null ? void 0 : e.label) || "数据",
        type: "map",
        map: t,
        roam: !0,
        label: {
          show: !0,
          color: "#fff",
          fontSize: 10
        },
        itemStyle: {
          areaColor: "#323c48",
          borderColor: "#111"
        },
        emphasis: {
          label: { color: "#fff" },
          itemStyle: { areaColor: "#2a333d" }
        },
        data: h || []
      }]
    };
  };
  return p ? /* @__PURE__ */ n("div", { style: {
    width: "100%",
    height: "100%",
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    color: "#999"
  }, children: "加载地图中..." }) : c ? /* @__PURE__ */ n("div", { style: {
    width: "100%",
    height: "100%",
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    color: "#ff4d4f"
  }, children: c }) : y ? /* @__PURE__ */ n(
    x,
    {
      option: m(),
      style: { width: "100%", height: "100%" },
      opts: { renderer: "svg" }
    },
    t
  ) : null;
}
export {
  I as default
};
//# sourceMappingURL=MapChart-Chz86Cdw.mjs.map
