function _(s,e,i,r){function n(t){return t instanceof i?t:new i(function(o){o(t)})}return new(i||(i=Promise))(function(t,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?t(a.value):n(a.value).then(l,u)}c((r=r.apply(s,[])).next())})}function P(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var j=function s(e,i){if(e===i)return!0;if(e&&i&&typeof e=="object"&&typeof i=="object"){if(e.constructor!==i.constructor)return!1;var r,n,t;if(Array.isArray(e)){if(r=e.length,r!=i.length)return!1;for(n=r;n--!==0;)if(!s(e[n],i[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===i.source&&e.flags===i.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===i.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===i.toString();if(t=Object.keys(e),r=t.length,r!==Object.keys(i).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(i,t[n]))return!1;for(n=r;n--!==0;){var o=t[n];if(!s(e[o],i[o]))return!1}return!0}return e!==e&&i!==i},A=P(j);const S="__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:i,channel:r,client:n,id:t=S,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=i,this.channel=r,this.client=n,this.id=t||S,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+=`®ion=${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,i)=>{this.loadCallback(r=>{r?i(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,i;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(t=>!r[t]&&delete r[t]),!((i=(e=window==null?void 0:window.google)===null||e===void 0?void 0:e.maps)===null||i===void 0)&&i.importLibrary||(t=>{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={}),E=new Set,v=new URLSearchParams,k=()=>o||(o=new Promise((b,w)=>_(this,void 0,void 0,function*(){var I;yield l=d.createElement("script"),l.id=this.id,v.set("libraries",[...E]+"");for(u in t)v.set(u.replace(/[A-Z]/g,O=>"_"+O[0].toLowerCase()),t[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:",t):y[h]=(b,...w)=>E.add(b)&&k().then(()=>y[h](b,...w))})(r);const n=this.libraries.map(t=>this.importLibrary(t));n.length||n.push(this.importLibrary("core")),Promise.all(n).then(()=>this.callback(),t=>{const o=new ErrorEvent("error",{error:t});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 i=this.errors.length*Math.pow(2,this.errors.length);console.error(`Failed to load Google Maps script, retrying in ${i} ms.`),setTimeout(()=>{this.deleteScript(),this.setScript()},i)}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()}}}export{p as L};