import{a as d,u as m,d as u,b as g}from"./app-core.ae890a3f.js";import{u as f,g as k,f as n,i as l,j as c,V as b,M as p}from"./vendor-vue-ui.de3ab35f.js";import{_ as y}from"./_plugin-vue_export-helper.eefbdd86.js";import{v as h,k as w}from"./vendor-lodash.8e35bd59.js";import{_}from"./vendor-other.7b559694.js";const D=()=>({getDataObject:f(()=>{const e=k(),a=d(),s=m();return e?.root?.data?.screenContext==="metabox"?s.currentPost.local_seo.maps:a.options.localBusiness.maps})});function z(t,e,a){return!t||!e?Promise.resolve(!1):e==="places/embed"?a.post(u.restUrl("local-business/maps/check-api-enabled")).send({apiKey:t,apiName:e}).then(s=>s.statusCode===200).catch(s=>!1):Promise.resolve(!1)}async function M(t,e,a){if(!t?.maps)return!1;let s=null;switch(e){case"places":return t.maps.places?(s=new t.maps.places.AutocompleteService,new Promise(i=>{s.getQueryPredictions({input:a||"NYC"},function(o,r){i(r===t.maps.places.PlacesServiceStatus.OK)})})):!1;case"geocoder":return s=new t.maps.Geocoder,new Promise(i=>{s.geocode({address:a||"NYC"},function(o,r){r===t.maps.GeocoderStatus.OK&&i({enabled:!0,result:o[0].geometry.location}),i({enabled:!1})})});default:return!1}}class I{url="https://maps.googleapis.com/maps/api/js";scriptId="localseo-maps-script";loading=!1;googleMapCallback="aioseoGoogleMapsLoaded";callbacks=[];constructor({apiKey:e,version:a,libraries:s}){this.apiKey=e,this.version=a||"weekly",this.libraries=s||[]}createUrl(){let e=this.url;return e+=`?callback=${this.googleMapCallback}`,this.apiKey&&(e+=`&key=${this.apiKey}`),0{this.loadCallback(s=>{s?a(s):e(window.google)})})}loadCallback(e){this.callbacks.push(e),this.execute()}setCallback(){window.aioseoGoogleMapsLoaded=this.callback.bind(this)}callback(){this.loading=!1,this.callbacks.forEach(e=>{e(this.onerrorEvent)}),this.callbacks=[]}setScript(){this.reset();const e=this.createUrl(),a=document.createElement("script");a.id=this.scriptId,a.type="text/javascript",a.src=e,a.onerror=this.loadErrorCallback.bind(this),a.defer=!0,a.async=!0,this.nonce&&(a.nonce=this.nonce),document.head.appendChild(a)}loadErrorCallback(e){this.onerrorEvent=e,this.callback()}reset(){this.deleteScript(),window.google&&window.google.maps&&(window.google.maps=null)}deleteScript(){const e=document.getElementById(this.scriptId);e&&e.remove()}execute(){this.setCallback(),this.setScript()}}const v="aioseo-pro",S={emits:["zoom-changed","marker-position-changed","map-loaded","places-library-available","place-information","click"],setup(){return{rootStore:g()}},props:{apiKey:String,options:Object,marker:Object,placeId:String,address:String,searchBox:{type:Boolean,default(){return!1}},preventInteraction:{type:Boolean,default(){return!1}},watchOptions:{type:Boolean,default(){return!1}}},data(){return{mapDivId:null,mapSearchBoxId:null,google:null,map:null,mapMarker:null,loader:null,placesLibraryAvailable:!1,strings:{map:_("Map",v)}}},watch:{marker(){this.mapMarker&&this.changeIcon(this.marker.icon)},"options.mapTypeId":{handler:function(){this.map.setOptions(this.options)}},apiKey(){this.loadMap()}},methods:{createMap(){this.map=new this.google.maps.Map(document.getElementById(this.mapDivId),this.options),this.map.addListener("zoom_changed",()=>{this.$emit("zoom-changed",this.map.getZoom())}),this.map.addListener("click",t=>{this.$emit("click",t),this.mapMarker&&(t.placeId?this.removeMarker():this.createMarker(t.latLng),this.placeInformation(t))})},createSearchBox(){if(!this.searchBox)return;const t=document.getElementById(this.mapSearchBoxId),e=new this.google.maps.places.SearchBox(t);this.map.controls[this.google.maps.ControlPosition.TOP_LEFT].push(t),e.addListener("places_changed",()=>{const a=e.getPlaces();if(a.length===0)return;this.removeMarker();const s=new this.google.maps.LatLngBounds;a.forEach(i=>{if(!i.geometry||!i.geometry.location){console.warn("Returned place contains no geometry");return}this.createMarker(i.geometry.location),i.geometry.viewport?s.union(i.geometry.viewport):s.extend(i.geometry.location)}),this.map.fitBounds(s)})},changeIcon(t){if(!t){this.mapMarker.setIcon(null);return}this.mapMarker.setIcon({url:t,size:new this.google.maps.Size(25,25),origin:new this.google.maps.Point(0,0),anchor:new this.google.maps.Point(17,34),scaledSize:new this.google.maps.Size(25,25)})},createMarker(t,e=!1){this.mapMarker||(this.mapMarker=new this.google.maps.Marker({map:this.map,draggable:!0}),this.mapMarker.addListener("position_changed",()=>{this.placeInformation({latLng:this.mapMarker.getPosition()}),this.$emit("marker-position-changed",this.mapMarker.getPosition())})),t&&(this.mapMarker.setPosition(t),e&&this.map.setCenter(t)),this.changeIcon(this.marker.icon),this.mapMarker.setMap(this.map)},removeMarker(){this.mapMarker&&this.mapMarker.setMap(null)},loadMap(){(typeof window.google<"u"&&typeof window.google.maps<"u"&&typeof window.google.maps.plugins<"u"&&typeof window.google.maps.plugins.loader<"u"?new window.google.maps.plugins.loader.Loader({apiKey:this.apiKey,libraries:["places"]}):new I({apiKey:this.apiKey,libraries:["places"]})).load().then(e=>{this.google=e,this.createMap(),this.createMarker(),!this.placeId&&this.marker&&this.createMarker(this.marker.position),this.libraryEnabled("places").then(a=>{this.$emit("places-library-available",a),a&&(this.placesLibraryAvailable=!0,this.createSearchBox())}),this.$emit("map-loaded"),this.placeInformation({placeId:this.placeId,latLng:this.marker.position})})},placeInformation(t){typeof t.latLng<"u"&&typeof t.latLng.lat=="function"&&(t.latLng=t.latLng.toJSON()),this.$emit("place-information",t)},libraryEnabled(t,e){return M(this.google,t,e)},isMarkerDefault(){return this.marker&&w(this.marker.position,this.rootStore.aioseo.localBusiness.mapDefaults.center)}},mounted(){this.apiKey&&(this.mapDivId=h("map_"),this.mapSearchBoxId=h("search_box_"),this.loadMap())}},x={class:"mapBox"},B=["id"],L=["id"],C={key:1,class:"preventInteraction"};function E(t,e,a,s,i,o){return n(),l("div",null,[c("div",x,[a.searchBox?(n(),l("input",{key:0,class:"searchInput",id:i.mapSearchBoxId,style:b({display:i.placesLibraryAvailable?"block":"none"})},null,12,B)):p("",!0),c("div",{id:i.mapDivId,class:"map"},null,8,L),a.preventInteraction?(n(),l("div",C)):p("",!0)])])}const A=y(S,[["render",E],["__scopeId","data-v-9a86271f"]]);export{A as C,z as i,D as u};