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