// 内库使用-start
import LocaleUtil from "./../../../../../utils/LocaleUtil";
import AssetUtil from "./../../../../../utils/AssetUtil";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil, AssetUtil } from 'seedsui-react'
测试使用-end */

// 加载BMap地图资源
function loadBMap(key) {
  return new Promise(function (resolve) {
    if (window.BMap) {
      resolve(window.BMap);
      return;
    }

    // Delete old script
    var scriptTag = document.getElementById('bmap-map-js');
    if (scriptTag) {
      scriptTag.parentNode.removeChild(scriptTag);
    }

    // Load js
    AssetUtil.loadJs("https://api.map.baidu.com/api?v=3.0&ak=".concat(key, "&callback=&callback=onBMapLoad"), {
      id: 'bmap-map-js',
      success: function success() {
        window.onBMapLoad = function () {
          if (window.BMap) {
            resolve(window.BMap);
          } else {
            resolve(LocaleUtil.locale("\u5730\u56FE\u5E93\u52A0\u8F7D\u5931\u8D25, \u8BF7\u7A0D\u540E\u518D\u8BD5", 'SeedsUI_map_js_load_failed'));
          }
        };
      },
      fail: function fail() {
        resolve(LocaleUtil.locale("\u5730\u56FE\u5E93\u52A0\u8F7D\u5931\u8D25, \u8BF7\u7A0D\u540E\u518D\u8BD5", 'SeedsUI_map_js_load_failed'));
      }
    });
  });
}
export default loadBMap;