import AMapLoader from "@amap/amap-jsapi-loader";

let AMapInstance: any = null;

export async function loadAMap(): Promise<any> {
  if (AMapInstance) return AMapInstance;

  return AMapLoader.load({
    key: import.meta.env.VITE_AMAP_KEY,
    version: "2.0",
    plugins: [
      "AMap.Geolocation",
      "AMap.Scale",
      "AMap.ToolBar",
      "AMap.Marker",
      "AMap.InfoWindow",
      "AMap.Geocoder",
    ],
  }).then((AMap: any) => {
    AMapInstance = AMap;
    return AMap;
  });
}
