import { jsxs as g, jsx as o } from "react/jsx-runtime";
import { useState as h, useRef as E, useEffect as B } from "react";
import { E as I, r as L } from "./index-BucR6RTl.mjs";
import { g as T, h as V, b as F } from "./mapData-Cg2oKcpf.mjs";
function q({
  cityName: e = "nanjing",
  mapData: s,
  chartTitle: m,
  showBuiltinData: w = !0,
  colorScheme: b = "blue"
}) {
  const [D, l] = h(!0), [y, c] = h(null), [$, v] = h(!1), j = E(/* @__PURE__ */ new Set()), z = {
    blue: {
      colors: ["#e1f5fe", "#4fc3f7", "#29b6f6", "#0288d1", "#0277bd"],
      visualMap: ["#81d4fa", "#0288d1", "#01579b"]
    },
    green: {
      colors: ["#e8f5e8", "#66bb6a", "#4caf50", "#388e3c", "#2e7d32"],
      visualMap: ["#a5d6a7", "#4caf50", "#1b5e20"]
    },
    red: {
      colors: ["#ffebee", "#ef5350", "#f44336", "#d32f2f", "#c62828"],
      visualMap: ["#ffcdd2", "#f44336", "#b71c1c"]
    },
    purple: {
      colors: ["#f3e5f5", "#ab47bc", "#9c27b0", "#7b1fa2", "#6a1b9a"],
      visualMap: ["#ce93d8", "#9c27b0", "#4a148c"]
    },
    orange: {
      colors: ["#fff3e0", "#ffa726", "#ff9800", "#f57c00", "#ef6c00"],
      visualMap: ["#ffcc02", "#ff9800", "#e65100"]
    }
  };
  B(() => {
    let t = !1;
    return (async () => {
      var i, f, r, x, C, M, S;
      if (l(!0), c(null), v(!1), !T(e)) {
        c("未找到城市配置"), l(!1);
        return;
      }
      try {
        const u = (/* @__PURE__ */ new Date()).getTime(), k = `/map/${e}.json?t=${u}`, p = await fetch(k, {
          cache: "no-cache",
          headers: {
            "Cache-Control": "no-cache",
            Pragma: "no-cache"
          }
        });
        if (!p.ok)
          throw new Error(`加载失败: ${p.status}`);
        const n = await p.json();
        if (t) return;
        console.log(`${e} 地图数据:`, {
          type: n.type,
          features: (i = n.features) == null ? void 0 : i.length,
          firstFeature: (x = (r = (f = n.features) == null ? void 0 : f[0]) == null ? void 0 : r.properties) == null ? void 0 : x.name,
          geometryType: (S = (M = (C = n.features) == null ? void 0 : C[0]) == null ? void 0 : M.geometry) == null ? void 0 : S.type
        }), L(e, n), j.current.add(e), v(!0), l(!1);
      } catch (u) {
        if (t) return;
        console.error("城市地图加载失败:", u), c("城市地图数据加载失败"), l(!1);
      }
    })(), () => {
      t = !0;
    };
  }, [e]);
  const R = () => s && s.length > 0 ? s : w && V(e) ? F(e) : [], W = () => {
    const t = R(), d = z[b], a = t.map((r) => r.value), i = a.length > 0 ? Math.min(...a) : 0, f = a.length > 0 ? Math.max(...a) : 100;
    return {
      backgroundColor: "transparent",
      title: m ? {
        text: m,
        left: "center",
        top: 10,
        textStyle: {
          color: "#fff",
          fontSize: 16
        }
      } : void 0,
      tooltip: {
        trigger: "item",
        formatter: (r) => `${r.name}: ${r.value || "暂无数据"}`,
        backgroundColor: "rgba(0, 0, 0, 0.8)",
        borderColor: d.visualMap[1],
        borderWidth: 1,
        textStyle: {
          color: "#fff"
        }
      },
      visualMap: t.length > 0 ? {
        min: i,
        max: f,
        left: 20,
        bottom: 30,
        text: ["高", "低"],
        calculable: !0,
        inRange: {
          color: d.visualMap
        },
        textStyle: {
          color: "#fff",
          fontSize: 12
        },
        itemWidth: 15,
        itemHeight: 100
      } : void 0,
      series: [{
        name: "区县数据",
        type: "map",
        map: e,
        roam: !0,
        scaleLimit: {
          min: 0.8,
          max: 3
        },
        data: t,
        label: {
          show: !0,
          color: "#fff",
          fontSize: 11,
          fontWeight: "normal"
        },
        itemStyle: {
          areaColor: "#1e3a5f",
          borderColor: "#4a90e2",
          borderWidth: 1
        },
        emphasis: {
          label: {
            show: !0,
            color: "#fff",
            fontSize: 12,
            fontWeight: "bold"
          },
          itemStyle: {
            areaColor: "#2d5aa0",
            borderColor: "#66b3ff",
            borderWidth: 2
          }
        },
        select: {
          label: {
            show: !0,
            color: "#fff"
          },
          itemStyle: {
            areaColor: "#2d5aa0"
          }
        }
      }]
    };
  };
  return D ? /* @__PURE__ */ g("div", { style: {
    width: "100%",
    height: "100%",
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "center",
    color: "#4a90e2",
    background: "linear-gradient(135deg, #1e3c72 0%, #2a5298 100%)"
  }, children: [
    /* @__PURE__ */ o("div", { style: { fontSize: "24px", marginBottom: "10px" }, children: "🏙️" }),
    /* @__PURE__ */ o("div", { children: "加载城市地图中..." })
  ] }) : y ? /* @__PURE__ */ g("div", { style: {
    width: "100%",
    height: "100%",
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "center",
    color: "#ff6b6b",
    background: "linear-gradient(135deg, #1e3c72 0%, #2a5298 100%)"
  }, children: [
    /* @__PURE__ */ o("div", { style: { fontSize: "24px", marginBottom: "10px" }, children: "❌" }),
    /* @__PURE__ */ o("div", { children: y }),
    /* @__PURE__ */ g("div", { style: { fontSize: "12px", marginTop: "10px", opacity: 0.7 }, children: [
      "请检查 ",
      e,
      " 的地图数据文件"
    ] })
  ] }) : $ ? /* @__PURE__ */ o("div", { style: { width: "100%", height: "100%", position: "relative" }, children: /* @__PURE__ */ o(
    I,
    {
      option: W(),
      style: { width: "100%", height: "100%" },
      opts: { renderer: "svg" }
    },
    `${e}-${b}`
  ) }) : null;
}
export {
  q as default
};
//# sourceMappingURL=CityMapChart-D2AguoOn.mjs.map
