/**
 * @Author: Caow
 * @Date: 2020-04-22 19:44:30
 */

import { initMixin, initUse } from './global-api'

// global namespace
let BC = {
  version: __VERSION__,
  accessToken: '',
  author: __AUTHOR__,
  home_page: __HOME_PAGE__,
  Namespace: {},
  Initialized: false
}

// init global api
initMixin(BC)
initUse(BC)
require('../LICENSE')

// load Cesium
let cesiumLoaded = false
BC.init = callback => {
  if (!cesiumLoaded) {
    new Promise((resolve, reject) => {
      let Cesium = require('cesium/Cesium')
      resolve(Cesium)
    })
      .then(Cesium => {
        BC.Namespace['Cesium'] = Cesium
        cesiumLoaded = true
        delete window.Cesium
        callback && callback()
      })
      .catch(e => {})
  } else {
    callback && callback()
  }
}

export default BC
