function k(s,e,t,r){function n(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function l(a){try{c(r.next(a))}catch(h){o(h)}}function u(a){try{c(r.throw(a))}catch(h){o(h)}}function c(a){a.done?i(a.value):n(a.value).then(l,u)}c((r=r.apply(s,[])).next())})}function j(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var P=function s(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor!==t.constructor)return!1;var r,n,i;if(Array.isArray(e)){if(r=e.length,r!=t.length)return!1;for(n=r;n--!==0;)if(!s(e[n],t[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if(i=Object.keys(e),r=i.length,r!==Object.keys(t).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[n]))return!1;for(n=r;n--!==0;){var o=i[n];if(!s(e[o],t[o]))return!1}return!0}return e!==e&&t!==t},A=j(P);const E="__googleMapsScriptId";var f;(function(s){s[s.INITIALIZED=0]="INITIALIZED",s[s.LOADING=1]="LOADING",s[s.SUCCESS=2]="SUCCESS",s[s.FAILURE=3]="FAILURE"})(f||(f={}));class p{constructor({apiKey:e,authReferrerPolicy:t,channel:r,client:n,id:i=E,language:o,libraries:l=[],mapIds:u,nonce:c,region:a,retries:h=3,url:m="https://maps.googleapis.com/maps/api/js",version:d}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=e,this.authReferrerPolicy=t,this.channel=r,this.client=n,this.id=i||E,this.language=o,this.libraries=l,this.mapIds=u,this.nonce=c,this.region=a,this.retries=h,this.url=m,this.version=d,p.instance){if(!A(this.options,p.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(p.instance.options)}`);return p.instance}p.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?f.FAILURE:this.done?f.SUCCESS:this.loading?f.LOADING:f.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+="?callback=__googleMapsCallback&loading=async",this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`&region=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),this.authReferrerPolicy&&(e+=`&auth_referrer_policy=${this.authReferrerPolicy}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise((e,t)=>{this.loadCallback(r=>{r?t(r.error):e(window.google)})})}importLibrary(e){return this.execute(),google.maps.importLibrary(e)}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){var e,t;if(document.getElementById(this.id)){this.callback();return}const r={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(r).forEach(i=>!r[i]&&delete r[i]),!((t=(e=window==null?void 0:window.google)===null||e===void 0?void 0:e.maps)===null||t===void 0)&&t.importLibrary||(i=>{let o,l,u,c="The Google Maps JavaScript API",a="google",h="importLibrary",m="__ib__",d=document,g=window;g=g[a]||(g[a]={});const y=g.maps||(g.maps={}),S=new Set,v=new URLSearchParams,O=()=>o||(o=new Promise((b,w)=>k(this,void 0,void 0,function*(){var I;yield l=d.createElement("script"),l.id=this.id,v.set("libraries",[...S]+"");for(u in i)v.set(u.replace(/[A-Z]/g,_=>"_"+_[0].toLowerCase()),i[u]);v.set("callback",a+".maps."+m),l.src=this.url+"?"+v,y[m]=b,l.onerror=()=>o=w(Error(c+" could not load.")),l.nonce=this.nonce||((I=d.querySelector("script[nonce]"))===null||I===void 0?void 0:I.nonce)||"",d.head.append(l)})));y[h]?console.warn(c+" only loads once. Ignoring:",i):y[h]=(b,...w)=>S.add(b)&&O().then(()=>y[h](b,...w))})(r);const n=this.libraries.map(i=>this.importLibrary(i));n.length||n.push(this.importLibrary("core")),Promise.all(n).then(()=>this.callback(),i=>{const o=new ErrorEvent("error",{error:i});this.loadErrorCallback(o)})}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const t=this.errors.length*Math.pow(2,this.errors.length);console.error(`Failed to load Google Maps script, retrying in ${t} ms.`),setTimeout(()=>{this.deleteScript(),this.setScript()},t)}else this.onerrorEvent=e,this.callback()}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach(e=>{e(this.onerrorEvent)}),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),!this.loading)if(this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version){console.warn("Google Maps already loaded outside @googlemaps/js-api-loader. This may result in undesirable behavior as options and script parameters may not match."),this.callback();return}this.loading=!0,this.setScript()}}}const R=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_ID:E,Loader:p,get LoaderStatus(){return f}},Symbol.toStringTag,{value:"Module"}));export{R as G};
