var ACF_OSM_Map=function(){function t(t){this.map=null,this.map_component=t,this.map_element=this.map_component.classList.contains("osm_map_item")?this.map_component:this.map_component.querySelector(".osm_map_item"),this.coords_input=this.map_component.querySelector(".nr_address_coords"),this.lat=this.map_element.getAttribute("data-lat"),this.long=this.map_element.getAttribute("data-long"),this.scale=this.map_element.getAttribute("data-scale"),this.marker_image=this.map_element.getAttribute("data-marker-image"),this.coordinates=[parseFloat(this.long),parseFloat(this.lat)],this.zoom=this.map_element.getAttribute("data-zoom"),this.geocoder_status=this.map_component.getAttribute("data-geocoder"),this.resetButton=this.map_component.querySelector(".acf_osm_map_reset_btn")}var e=t.prototype;return e.getGeocoderStatus=function(){return this.geocoder_status},e.render=function(){var t=[],e=this.getScaleControl();e&&t.push(e),this.map=new ol.Map({controls:ol.control.defaults({attribution:!0}).extend(t),layers:[new ol.layer.Tile({source:new ol.source.OSM})],target:this.map_element,view:new ol.View({center:ol.proj.transform(this.getCoordinates(),"EPSG:4326","EPSG:3857"),zoom:parseInt(this.zoom)})}),this.handleResize()},e.addMarkerPopup=function(){var n=this.map_component.parentElement.querySelector(".marker-tooltip");if(n){var a=new ol.Overlay({element:n,positioning:"bottom-center",stopEvent:!0});this.map.addOverlay(a),this.map.addEventListener("click",function(t){var e=this.map.forEachFeatureAtPixel(t.pixel,function(t,e){return t});if(e){var o=e.getGeometry().getCoordinates();n.style.display="block",a.setOffset([0,-35]),a.setPosition(o)}else n.style.display="none"}.bind(this))}},e.getScaleControl=function(){if(this.scale&&"0"!=this.scale)return new ol.control.ScaleLine({units:this.scale})},e.handleClearButton=function(){if(!this.resetButton)return!1;this.resetButton.addEventListener("click",function(t){this.coords_input.value="",this.map_component.querySelector(".acf-map-coordinates-setting").classList.add("is-hidden"),t.preventDefault()}.bind(this))},e.handleGeocoderAddressUpdate=function(){this.map_component.querySelector(".ol-geocoder").addEventListener("click",function(t){var e=t.target,o="";"a"===e.tagName.toLowerCase()?o=e.querySelector("span").innerHTML:e.closest("a")&&(o=e.innerHTML),o&&(this.map_component.querySelector(".gcd-txt-input").value=o)}.bind(this))},e.handleResize=function(){window.addEventListener("resize",function(){})},e.addGeocoder=function(){this.geocoder=new Geocoder("nominatim",{provider:"osm",lang:Joomla.getOptions("com_acf_osm_admin").lang_tag,autoComplete:!0,autoCompleteMinLength:3,placeholder:Joomla.JText._("ACF_OSM_ADDRESS_DESC"),targetType:"text-input",limit:5,keepOpen:!0,featureStyle:new ol.style.Style({zIndex:-100}),preventDefault:!0}),this.map.addControl(this.geocoder)},e.handleGeocoderEvent=function(){var o=this;this.geocoder.on("addresschosen",function(t){var e=t.coordinate;o.updateCoordinates(e),o.setCenter(),o.map.getView().animate({zoom:o.map.getView().getZoom(),center:e})})},e.addMarker=function(){var t=new ol.Feature({geometry:new ol.geom.Point(ol.proj.fromLonLat([this.long,this.lat]))});t.setStyle(new ol.style.Style({image:new ol.style.Icon({src:this.marker_image})}));var e=new ol.layer.Vector({source:new ol.source.Vector({features:[t]})});this.marker={feature:t,vector:e},this.map.addLayer(this.marker.vector)},e.onMarkerDrag=function(){var e=this,t=new ol.interaction.Translate({features:new ol.Collection([this.marker.feature])});this.map.addInteraction(t),t.on("translatestart",function(t){}),t.on("translating",function(t){}),t.on("translateend",function(t){e.updateCoordinates(t.coordinate)})},e.onMapClickUpdateMarker=function(){var e=this;this.map.on("click",function(t){e.updateCoordinates(t.coordinate),e.setCenter()})},e.setCoordinates=function(t){this.coordinates=ol.proj.transform(t,"EPSG:3857","EPSG:4326")},e.getCoordinates=function(){return this.coordinates},e.updateCoordinates=function(t){this.setCoordinates(t),this.updateCoordinatesInput()},e.updateCoordinatesInput=function(){var t=this.getCoordinates();this.coords_input&&(t=[t[1],t[0]],this.coords_input.value=t.toString()),this.resetButton.classList.remove("is-hidden"),this.map_component.querySelector(".acf-map-coordinates-setting").classList.remove("is-hidden")},e.setCenter=function(){var t=this.getCoordinates();this.marker.feature.setGeometry(new ol.geom.Point(ol.proj.fromLonLat(t)))},e.getMapItem=function(){return this.map},t}();

