/**
* @package DPCalendar
* @copyright Digital Peak GmbH. <https://www.digital-peak.com>
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*/
!function(){"use strict";var e=!1;document.addEventListener("DOMContentLoaded",(function(){loadDPAssets(["/com_dpcalendar/js/dpcalendar/dpcalendar.js","/com_dpcalendar/js/dpcalendar/layouts/block/autocomplete.js","/com_dpcalendar/js/dpcalendar/layouts/block/select.js"],(function(){var t=document.getElementById("jform_geocomplete"),n=document.querySelector(".dp-map"),o=function(){if(n.dpmap.dpMarkers.length||DPCalendar.Map.createMarker(n,{latitude:document.getElementById("jform_latitude").value,longitude:document.getElementById("jform_longitude").value,color:document.getElementById("jform_color").value},(function(e,t){e&&(document.getElementById("jform_latitude").value=e),t&&(document.getElementById("jform_longitude").value=t)})),n.dpmap.dpMarkers.length)return n.dpmap.dpMarkers[0]};null!=n&&(n.addEventListener("dp-map-loaded",(function(){[].slice.call(document.querySelectorAll("#jform_street,#jform_number,#jform_zip,#jform_city,#jform_country,#jform_province")).forEach((function(a){a.addEventListener("change",(function(){if(!e){t.value="";var a="location.loc";-1==window.location.href.indexOf("administrator")&&(a="locationform.loc"),DPCalendar.request("task="+a+"&loc="+encodeURIComponent(function(){var e=function(e){var t=document.getElementById("jform_"+e);return t&&"SELECT"===t.tagName?t.options[t.selectedIndex].innerHTML+", ":t?t.value+", ":""},t=e("street");if(t){var n=e("number");n&&(t=t.substring(0,t.length-2)+" "+n)}var o=e("city");if(o){var a=e("zip");a&&(o+=o.substring(0,o.length-2)+" "+a)}return t+o+e("province")+e("country")}()),(function(e){e.data.latitude?(document.getElementById("jform_latitude").value=e.data.latitude,document.getElementById("jform_longitude").value=e.data.longitude,DPCalendar.Map.moveMarker(n,o(),e.data.latitude,e.data.longitude)):(document.getElementById("jform_latitude").value=0,document.getElementById("jform_longitude").value=0)}),!0)}}))})),window.jQuery&&jQuery("#jform_color").change((function(){DPCalendar.Map.clearMarkers(n),o()})),document.getElementById("jform_color").addEventListener("change",(function(){DPCalendar.Map.clearMarkers(n),o()})),o()})),[n].forEach((function(e){"IntersectionObserver"in window!=0?new IntersectionObserver((function(t,n){t.forEach((function(t){t.isIntersecting&&(n.unobserve(e),loadDPAssets(["/com_dpcalendar/js/dpcalendar/map.js"],(function(){return DPCalendar.Map.create(e)})))}))})).observe(e):loadDPAssets(["/com_dpcalendar/js/dpcalendar/map.js"],(function(){return DPCalendar.Map.create(e)}))}))),DPCalendar.autocomplete.create(t),t.addEventListener("dp-autocomplete-select",(function(t){var a="location.loc";-1==window.location.href.indexOf("administrator")&&(a="locationform.loc"),DPCalendar.request("task="+a+"&loc="+encodeURIComponent(t.detail.value),(function(t){t.data&&(!function(t){[].slice.call(document.querySelectorAll(".com-dpcalendar-locationform__fields .dp-form-input")).forEach((function(e){"jform_title"!=e.id&&"jform_geocomplete"!=e.id&&(e.value="")})),document.getElementById("jform_country")&&(document.getElementById("jform_country").value=t.country,e=!0,document.getElementById("jform_country").dispatchEvent(new Event("change")),e=!1);document.getElementById("jform_number")&&(document.getElementById("jform_number").value=t.number);document.getElementById("jform_street")&&(document.getElementById("jform_street").value=t.street);document.getElementById("jform_city")&&(document.getElementById("jform_city").value=t.city);document.getElementById("jform_province")&&(document.getElementById("jform_province").value=t.province);document.getElementById("jform_zip")&&(document.getElementById("jform_zip").value=t.zip);document.getElementById("jform_latitude").value=t.latitude,document.getElementById("jform_longitude").value=t.longitude,""==document.getElementById("jform_title").value&&(document.getElementById("jform_title").value=t.formatted)}(t.data),DPCalendar.Map&&DPCalendar.Map.moveMarker(n,o(),t.data.latitude,t.data.longitude))}),!0)})),t.addEventListener("dp-autocomplete-change",(function(e){var n="location.searchloc";-1==window.location.href.indexOf("administrator")&&(n="locationform.searchloc"),DPCalendar.request("task="+n+"&loc="+encodeURIComponent(e.target.value.trim()),(function(e){DPCalendar.autocomplete.setItems(t,e.data)}),!0)})),t.parentElement.querySelector(".dp-button-action").addEventListener("click",(function(e){return e.preventDefault(),t.dispatchEvent(new CustomEvent("dp-autocomplete-change",{value:t.value.trim()})),!1})),[].slice.call(document.querySelectorAll(".com-dpcalendar-locationform__actions .dp-button-action")).forEach((function(e){e.addEventListener("click",(function(){return Joomla.submitbutton("locationform."+e.getAttribute("data-task"))}))})),Joomla.submitbutton=function(e){var t=document.getElementsByName("adminForm")[0];t&&(e.indexOf("cancel")>-1||e.indexOf("delete")>-1||document.formvalidator.isValid(t))&&Joomla.submitform(e,t)}}))}))}();