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

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

// 加载地图资源
function loadLeaflet() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    css = _ref.css,
    js = _ref.js;
  return new Promise(function (resolve) {
    if (window.L) {
      resolve(window.L);
      return;
    }

    // Delete old css
    var cssTag = document.getElementById('leaflet-css');
    if (cssTag) {
      cssTag.parentNode.removeChild(cssTag);
    }

    // Load css
    var link = document.createElement('link');
    link.rel = 'stylesheet';
    // 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css'
    link.href = css || 'https://res.waiqin365.com/d/waiqin365_h5/seedsui/assets/plugin/leaflet/css/leaflet.css';
    link.id = 'leaflet-css';
    document.head.appendChild(link);

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

    // Load js
    // 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'
    AssetUtil.loadJs(js || 'https://res.waiqin365.com/d/waiqin365_h5/seedsui/assets/plugin/leaflet/js/leaflet.js', {
      id: 'leaflet-js',
      // integrity: 'sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=',
      // crossorigin: '',
      success: function success() {
        resolve(window.L);
      },
      fail: function fail() {
        resolve("leaflet\u52A0\u8F7D\u5931\u8D25");
      }
    });
  });
}
export default loadLeaflet;