document.addEventListener("DOMContentLoaded",()=>{mapboxgl.accessToken="pk.eyJ1IjoiZGF2c3J1a3MiLCJhIjoiY2twNThraXB0MmxzYzJwbXBkbXRvbTJ4OCJ9.-wHEkuPFDRlem6v4F1rXnw";let e=document.querySelector('[data-map-element="data"]'),t=e.dataset.mapCategory,a=parseFloat(e.dataset.mapLng),o=parseFloat(e.dataset.mapLat);if(Number.isNaN(o)||Number.isNaN(a)){console.error("Invalid latitude or longitude data.");return}let r={type:"Feature",geometry:{type:"Point",coordinates:[a,o]},properties:{category:t}},l={en:{"AttributionControl.ToggleAttribution":"Toggle attribution","LogoControl.Title":"Mapbox homepage","Map.Title":"Map","ScrollZoomBlocker.CtrlMessage":"Use Ctrl + scroll to zoom the map","ScrollZoomBlocker.CmdMessage":"Use ⌘ + scroll to zoom the map","TouchPanBlocker.Message":"Use two fingers to move the map","Marker.Label":"Map marker","Feedback.Text":"Improve this map"},lv:{"AttributionControl.ToggleAttribution":"Pārslēgt atribūciju","LogoControl.Title":"Mapbox mājaslapa","Map.Title":"Karte","ScrollZoomBlocker.CtrlMessage":"Turiet nospiestu Ctrl un izmantojiet peles rullīti, lai tuvinātu karti","ScrollZoomBlocker.CmdMessage":"Turiet nospiestu ⌘ un izmantojiet peles rullīti, lai tuvinātu karti","TouchPanBlocker.Message":"Pārvietojiet karti ar diviem pirkstiem","Marker.Label":"Kartes marķieris","Feedback.Text":"Uzlabot šo karti"}},i=window.location.pathname.split("/")[1],s=["lv"],n=s.includes(i)?i:"en",m=new mapboxgl.Map({container:"map",style:"mapbox://styles/davsruks/cmhyxms3u005o01s947wahlw2",center:[a,o],zoom:15,minZoom:4,maxZoom:18,locale:l[n],cooperativeGestures:!0});function c(){m.flyTo({center:[a,o],zoom:15,speed:1.4})}let p=document.createElement("button"),u=l[n]["Marker.Label"];p.setAttribute("type","button"),p.setAttribute("role","button"),p.setAttribute("aria-label",u);let d='[data-map-template="marker"]';if("wine-list"===t?d='[data-map-template="marker-wine-list"]':"drink-list"===t?d='[data-map-template="marker-drink-list"]':"retailer"===t&&(d='[data-map-template="marker-retailer"]'),d){let b=document.querySelector(d);if(b){let k=b.classList;k.forEach(e=>{p.classList.add(e)})}new mapboxgl.Marker(p).setLngLat(r.geometry.coordinates).addTo(m),p.addEventListener("click",e=>{c(),e.stopPropagation()})}m.on("load",()=>{m.setLanguage(n);let e=l[n]["Feedback.Text"],t=document.querySelector(".mapbox-improve-map");t&&(t.removeAttribute("title"),t.setAttribute("aria-label",e),t.textContent=e);let a=document.querySelector(".mapboxgl-touch-pan-blocker"),o=document.querySelector(".mapboxgl-scroll-zoom-blocker");a&&a.setAttribute("aria-hidden","true"),o&&o.setAttribute("aria-hidden","true");let r=document.querySelector('[data-map-element="zoom-in"]');r&&r.addEventListener("click",()=>{m.zoomIn()});let i=document.querySelector('[data-map-element="zoom-out"]');i&&i.addEventListener("click",()=>{m.zoomOut()}),document.getElementById("map").style.opacity="1"})});