import React__default, { useState, useEffect } from 'react';
import { logger } from '@zenview/micro-utils';

const cache = {};
function loadScript(url) {
  return new Promise((resolve, reject) => {
    if (cache[url]) {
      resolve();
    }
    const script = document.createElement('script');
    script.type = 'text/javascript';
    script.onload = function () {
      cache[url] = true;
      resolve();
    };
    script.onerror = function (err) {
      reject(err);
    };
    script.src = url;
    window._APPEND_CHILD_ ? window._APPEND_CHILD_(script) : document.head.appendChild(script);
  });
}

const ZenMapGL = '/micro-apps/micro-dep-librarys/map/zenmap/ZenMapGL.js';
const ZenMapGL_Extend = '/micro-apps/micro-dep-librarys/map/zenmap/ZenMapGL_Extend.js';
const threebox = '/micro-apps/micro-dep-librarys/map/zenmap/lib/threebox.js';
const BigScreenMap = '/micro-apps/micro-dep-librarys/map/zenmap/BigScreenMap.js';
function LoaderMap({
  children,
  fallback = null
}) {
  const [isInit, setInit] = useState(false);
  useEffect(() => {
    const loader = async () => {
      await loadScript(ZenMapGL);
      await loadScript(ZenMapGL_Extend);
      await loadScript(threebox);
      await loadScript(BigScreenMap);
    };
    loader().then(() => setInit(true)).catch(err => logger.debug('地图加载失败！', err));
  }, []);
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isInit ? children : fallback);
}

export { LoaderMap as default };
//# sourceMappingURL=index.js.map
