import { defineComponent as m, toRefs as x, ref as R, watch as f, onMounted as S, openBlock as K, createElementBlock as L } from "vue";
import O from "@amap/amap-jsapi-loader";
const b = m({ name: "EMapAmap" }), B = /* @__PURE__ */ m({
  ...b,
  props: {
    chartConfig: {
      type: Object,
      required: !0
    }
  },
  setup(v) {
    const t = v;
    let {
      amapKey: d,
      amapStyleKey: h,
      amapLon: y,
      amapLat: M,
      amapZindex: k,
      mapMarkerType: p,
      lang: C,
      amapStyleKeyCustom: i,
      features: g,
      viewMode: _,
      pitch: w,
      skyColor: A,
      marker: E
    } = x(t.chartConfig.option.mapOptions), o = null, l = [], r = null;
    const s = R(), u = (a) => {
      O.load({
        key: d.value,
        version: "1.4.8",
        plugins: ["AMap.PlaceSearch", "AMap.AutoComplete"]
      }).then((e) => {
        r = e, o = new e.Map(s.value, {
          resizeEnable: !0,
          zoom: k.value,
          center: [y.value, M.value],
          mapStyle: `amap://styles/${i.value !== "" ? i.value : h.value}`,
          lang: C.value,
          features: g.value,
          pitch: w.value,
          skyColor: A.value,
          viewMode: _.value,
          willReadFrequently: !0
        }), c(t.chartConfig.option.dataset);
      }).catch((e) => {
      });
    }, c = (a) => {
      if (!o && !r) {
        u(t.chartConfig.option);
        return;
      }
      Array.isArray(a.markers) && (o.remove(l), l = [], p.value === "Marker" ? a.markers.forEach((e) => {
        const n = new r.Marker({
          position: [e.position[0], e.position[1]],
          offset: new r.Pixel(-13, -30)
        });
        l.push(n), n.setMap(o);
      }) : p.value === "CircleMarker" && a.markers.forEach((e) => {
        const n = new r.CircleMarker({
          center: [e.position[0], e.position[1]],
          radius: e.value,
          ...E.value
        });
        l.push(n), n.setMap(o);
      }));
    };
    return f(
      () => t.chartConfig.option.mapOptions,
      (a) => {
        u();
      },
      {
        immediate: !0,
        deep: !0
      }
    ), f(
      () => t.chartConfig.option.dataset,
      (a) => {
        try {
          c(a);
        } catch (e) {
          console.log(e);
        }
      },
      {
        deep: !1
      }
    ), S(() => {
    }), (a, e) => (K(), L("div", {
      ref_key: "vChartRef",
      ref: s
    }, null, 512));
  }
});
export {
  B as default
};
