let promise = null
const id = 'google-cdn'
const url = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyB228FQfRMabWfIczMamI1NSYMJg2FqLts'
export default () => {
  if (!promise) {
    promise = new Promise((resolve, reject) => {
      if (document.getElementById(id)) {
        console.error(`Error loading ${url} async: ${id} is not unique`)
        return
      }
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.id = id
      script.onload = () => {
        resolve()
      }
      script.onerror = (err) => {
        reject(err)
      }
      document.body.appendChild(script)
    })
  }
  return promise
}
