window.GoogleMapsCore=class{constructor(e,t){this.el=e,this.config=t,this.config,this.doc=this.el.ownerDocument,this.map=null,this.activePopup=null,this.markers=[],this.markerCluster=null,this.geocoder=null,this.bounds=null,this.lastTriggerElement=null;this.config.baseUri;this.icons={normal:{url:"/wp-content/uploads/pin.svg",scaledSize:new google.maps.Size(36,36),anchor:new google.maps.Point(20,65)},active:{url:"/wp-content/uploads/pin-active.svg",scaledSize:new google.maps.Size(36,36),anchor:new google.maps.Point(20,65)},def:{url:"/wp-content/uploads/pin-def.svg",scaledSize:new google.maps.Size(20,20),anchor:new google.maps.Point(10,10)}}}initClusterer(){"undefined"!=typeof MarkerClusterer&&0<this.markers.length&&(this.markerCluster=new MarkerClusterer(this.map,this.markers,{imagePath:this.config.baseUri+"/images/m",gridSize:60,averageCenter:!0,clusterColor:this.config.clusterColor}))}async init(){this.definePopupClass(),this.geocoder=new google.maps.Geocoder,this.bounds=new google.maps.LatLngBounds;var e={center:{lat:51.1657,lng:10.4515},zoom:parseInt(this.config.zoom)||6,maxZoom:38,mapId:this.config.mapId||null,disableDefaultUI:!1,fullscreenControl:!1,zoomControl:!0,mapTypeControl:!1,streetViewControl:!1,mapTypeControlOptions:{mapTypeIds:[google.maps.MapTypeId.ROADMAP,"styled_map"]}};this.map=new google.maps.Map(this.el,e),this.config.mapStyle&&(e=new google.maps.StyledMapType(this.config.mapStyle,{name:"Custom Style"}),this.map.mapTypes.set("styled_map",e),this.map.setMapTypeId("styled_map")),google.maps.event.addListener(this.map,"idle",()=>{const e=this.map.getDiv();this.makeMarkersAccessible();const t=e.querySelectorAll('div[tabindex="0"], [role="button"]');t.forEach(e=>{var t=e.classList.contains("map-cluster-icon"),s=null!==e.getAttribute("title"),i=e.classList.contains("popup-bubble")||e.closest(".popup-bubble"),o=e.contains(this.doc.activeElement);t||s||i||o||(e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true"))})}),this.el.querySelectorAll(".js-is-deactivated").forEach(e=>e.style.display="none"),this.doc.getElementById("js-is-deactivated")?.style.setProperty("display","none"),this.doc.addEventListener("keydown",e=>{if("Escape"===e.key&&this.map&&this.map.getDiv().contains(this.doc.activeElement)){const t=this.doc.getElementById("reset-map-"+this.config.containerId);t?.focus()}}),this.initTabs(),this.initGlobalEvents()}makeMarkersAccessible(){const e=this.map.getDiv(),t=e.querySelectorAll('div[role="button"][title], .map-cluster-icon');t.forEach((t,e)=>{t.setAttribute("tabindex","0"),t.getAttribute("data-a11y-bound")||(t.setAttribute("data-a11y-bound","true"),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),t.classList.contains("map-cluster-icon")?t.click():(e=this.getMarkerByTitle(t.getAttribute("title")))&&google.maps.event.trigger(e,"click"))}))})}getMarkerByTitle(t){return this.markers.find(e=>e.getTitle()===t)}getHTML(e,t){if(window.GMapTemplates&&"function"==typeof window.GMapTemplates[e])return window.GMapTemplates[e](t);switch(e){case"locationItem":return`<div class="location-item"><h3>${t.name}</h3><p>${t.street}</p></div>`;case"popup":return`<div class="popup-info"><strong>${t.name}</strong></div>`;default:return""}}geocode(e){return new Promise((s,i)=>{if("string"!=typeof e||""===e.trim())return i(new Error("Geocode: Adresse muss ein String sein."));this.geocoder||(this.geocoder=new google.maps.Geocoder),this.geocoder.geocode({address:e},(e,t)=>{"OK"===t&&e[0]?s(e[0].geometry.location):i(new Error("Adresse nicht gefunden: "+t))})})}definePopupClass(){window.GooglePopup||(window.GooglePopup=class extends google.maps.OverlayView{constructor(e,t,s="",i=50){super(),this.position=e,this.className=s,this.offsetY=i,this.containerDiv=document.createElement("div"),this.containerDiv.classList.add("popup-container"),this.className&&this.containerDiv.classList.add(this.className);const o=document.createElement("div");o.classList.add("popup-bubble-anchor"),t instanceof HTMLElement?this.bubble=t:(this.bubble=document.createElement("div"),this.bubble.classList.add("popup-bubble"),this.bubble.innerHTML=t),o.appendChild(this.bubble),this.containerDiv.appendChild(o),google.maps.OverlayView.preventMapHitsAndGesturesFrom(this.containerDiv)}onAdd(){this.getPanes().floatPane.appendChild(this.containerDiv)}onRemove(){this.containerDiv.parentElement?.removeChild(this.containerDiv)}draw(){var e=this.getProjection().fromLatLngToDivPixel(this.position),t=Math.abs(e.x)<4e3&&Math.abs(e.y)<4e3,s=t?"block":"none";t&&(this.containerDiv.style.left=e.x+"px",this.containerDiv.style.top=e.y-this.offsetY+"px"),this.containerDiv.style.display!==s&&(this.containerDiv.style.display=s)}})}openPopup(e,t,s="",i=null){this.activePopup&&this.activePopup.setMap(null),this.resultMarker&&this.resultMarker.setMap(null);let o=45;i?.icon?.scaledSize&&(o=i.icon.scaledSize.height+25),i&&(this.resultMarker=new google.maps.Marker({position:e,map:this.map,...i}));const a=document.createElement("div");a.className="popup-bubble",a.setAttribute("tabindex","0"),a.setAttribute("role","dialog"),a.setAttribute("aria-label","Standort Information");const n=document.createElement("span");n.className="close-popup",n.innerHTML=" ",n.setAttribute("tabindex","0"),n.setAttribute("aria-label","Popup schließen");const r=()=>this.closeActivePopup();n.onclick=r,n.onkeydown=e=>{"Enter"!==e.key&&" "!==e.key||r()},a.appendChild(n);const l=document.createElement("div");l.className="popup-content-inner",l.innerHTML=t,a.appendChild(l),setTimeout(()=>a.focus(),200),this.activePopup=new window.GooglePopup(e,a,s,o),this.activePopup.setMap(this.map),this.centerMapWithOffset(e)}closeActivePopup(){this.activePopup&&(this.activePopup.setMap(null),this.activePopup=null),this.resultMarker&&this.resultMarker.setMap(null),this.lastTriggerElement?.focus&&this.lastTriggerElement.focus()}centerMapWithOffset(t){this.activePopup?.bubble?setTimeout(()=>{var e=this.activePopup.bubble.offsetHeight;this.map.panTo(t),this.map.panBy(0,-(e/2+50))},100):this.map.panTo(t)}reset(){this.closeActivePopup(),this.markerCluster&&(this.markerCluster.clearMarkers(),this.markerCluster=null),this.markers.forEach(e=>e.setMap(null)),this.markers=[],this.map.setZoom(parseInt(this.config.zoom)||6)}resetView(){this.activePopup&&this.closeActivePopup(),this.bounds&&!this.bounds.isEmpty()?this.map.fitBounds(this.bounds):(this.map.setZoom(parseInt(this.config.zoom)||6),this.map.setCenter({lat:51.1657,lng:10.4515}))}scrollToMap(){const e=this.doc.getElementById(this.config.containerId),t=e?.closest(".gmap-wrapper");if(t){var s=t.getBoundingClientRect().top+window.pageYOffset;let e=20;var i=this.doc.getElementById("wpadminbar");i&&(e+=i.offsetHeight);i=this.doc.querySelector(".header-sticky, .nav-fixed");i&&(e+=i.offsetHeight),window.scrollTo({top:s-e,behavior:"smooth"})}}initGlobalEvents(){this.doc.addEventListener("keydown",e=>{if("Escape"===e.key){const t=this.map.getDiv(),s=this.sidebar;(t.contains(this.doc.activeElement)||s?.contains(this.doc.activeElement))&&(this.closeActivePopup(),this.resetView(),this.doc.getElementById("location-input-"+this.config.containerId)?.focus())}})}initTabs(){const e=this.el.closest(".gmap-wrapper");if(e){const s=e.querySelectorAll(".map-tabs .tab-trigger"),i=e.querySelector(".grid-view"),o=e.querySelector(".map-view");s.forEach(t=>{t.addEventListener("click",e=>{e.preventDefault();e=t.dataset.target;s.forEach(e=>e.parentElement.classList.remove("uk-active")),t.parentElement.classList.add("uk-active"),"grid"===e?(o&&(o.style.display="none"),i&&(i.style.display="block")):(i&&(i.style.display="none"),o&&(o.style.display="block"),setTimeout(()=>{google.maps.event.trigger(this.map,"resize"),this.bounds&&!this.bounds.isEmpty()&&this.map.fitBounds(this.bounds)},50))})})}}};