/**
* @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;function t(){if(!e)if(document.getElementById("jform_scheduling")){var t=document.getElementById("jform_rrule").value;if(t){e=!0;var n=null;t.split(";").forEach((function(e){var t=e.split("=");if(0!==t.length)switch(t[0]){case"FREQ":[].slice.call(document.getElementById("jform_scheduling").querySelectorAll("input")).forEach((function(e){e.checked=e.value==t[1],e.value==t[1]&&(n=e.value),"DAILY"===t[1]&&(document.getElementById("jform_scheduling_daily_weekdays0").checked=!1,document.getElementById("jform_scheduling_daily_weekdays1").checked=!0)}));break;case"BYDAY":"WEEKLY"===n&&"MO,TU,WE,TH,FR"==t[1]&&(document.getElementById("jform_scheduling_daily_weekdays0").checked=!0,document.getElementById("jform_scheduling_daily_weekdays1").checked=!1,document.getElementById("jform_scheduling1").checked=!0),"WEEKLY"===n&&[].slice.call(document.querySelectorAll("#jform_scheduling_weekly_days option")).forEach((function(e){return e.selected=!1})),"MONTHLY"===n&&([].slice.call(document.querySelectorAll("#jform_scheduling_monthly_week option")).forEach((function(e){return e.selected=!1})),[].slice.call(document.querySelectorAll("#jform_scheduling_monthly_week_days option")).forEach((function(e){return e.selected=!1}))),t[1].split(",").forEach((function(e){if("WEEKLY"!==n){var t=e.length,d=e.substring(t-2,t),o=e.substring(0,t-2);-1==o&&(o="last"),o&&(document.querySelector('#jform_scheduling_monthly_week option[value="'+o+'"]').selected=!0),d&&(document.querySelector('#jform_scheduling_monthly_week_days option[value="'+d+'"]').selected=!0)}else document.querySelector('#jform_scheduling_weekly_days option[value="'+e+'"]').selected=!0})),"WEEKLY"===n&&document.getElementById("jform_scheduling_weekly_days").dispatchEvent(new Event("change")),"MONTHLY"===n&&(document.getElementById("jform_scheduling_monthly_week").dispatchEvent(new Event("change")),document.getElementById("jform_scheduling_monthly_week_days").dispatchEvent(new Event("change")));break;case"BYMONTHDAY":document.getElementById("jform_scheduling_monthly_options").querySelector('input[value="by_day"]').checked=!0,t[1].split(",").forEach((function(e){return document.querySelector('#jform_scheduling_monthly_days option[value="'+e+'"]').selected=!0})),document.getElementById("jform_scheduling_monthly_days").dispatchEvent(new Event("change"));break;case"COUNT":document.getElementById("jform_scheduling_repeat_count").value=t[1];break;case"INTERVAL":document.getElementById("jform_scheduling_interval").value=t[1];break;case"UNTIL":var d=document.getElementById("jform_scheduling_end_date"),o=dayjs.utc(t[1].replace("Z",""),"YYYYMMDDThhmmss");d.value=o.format(d.getAttribute("data-format")),d.setAttribute("data-date",o.format("YYYY-MM-DD"))}})),d(),e=!1}else d()}else d()}function n(){if(!e&&document.getElementById("jform_scheduling")){var t="";if(document.getElementById("jform_scheduling1").checked&&(t="FREQ=DAILY",document.getElementById("jform_scheduling_daily_weekdays0").checked&&(t="FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR")),document.getElementById("jform_scheduling2").checked){t="FREQ=WEEKLY";var n=[].slice.call(document.querySelectorAll("#jform_scheduling_weekly_days option:checked"));n.length>0&&(t+=";BYDAY=",n.forEach((function(e){return t+=e.value+","})),t=t.slice(0,-1))}if(document.getElementById("jform_scheduling3").checked)if(t="FREQ=MONTHLY",document.getElementById("jform_scheduling_monthly_options0").checked){var d=[].slice.call(document.querySelectorAll("#jform_scheduling_monthly_days option:checked"));d.length>0&&(t+=";BYMONTHDAY=",d.forEach((function(e){return t+=e.value+","})),t=t.slice(0,-1))}else{var o=[].slice.call(document.querySelectorAll("#jform_scheduling_monthly_week option:checked"));o.length>0&&(t+=";BYDAY=",o.forEach((function(e){var n=[].slice.call(document.querySelectorAll("#jform_scheduling_monthly_week_days option:checked"));if(0!=n.length){var d=e.value;"last"==d&&(d=-1),n.forEach((function(e){return t+=d+e.value+","}))}})),t.endsWith(",")&&(t=t.slice(0,-1)))}if(document.getElementById("jform_scheduling4").checked&&(t="FREQ=YEARLY"),t.length>1){var l=document.getElementById("jform_scheduling_interval").value;l>0&&(t+=";INTERVAL="+l);var c=document.getElementById("jform_scheduling_repeat_count").value;c>0&&(t+=";COUNT="+c);var a=document.getElementById("jform_scheduling_end_date"),r=dayjs(a.value,a.getAttribute("data-format"));r.isValid()&&(t+=";UNTIL="+r.format("YYYYMMDD")+"T235900Z")}var i=document.getElementById("jform_rrule").value;document.getElementById("jform_rrule").value=t,i!=t&&(e=!0,document.getElementById("jform_rrule").dispatchEvent(new Event("change")),e=!1)}}function d(){document.querySelector(".dp-field-rrule").classList.add("dp-control_hidden"),document.querySelector(".dp-field-exdates").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-end-date").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-interval").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-repeat-count").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-daily-weekdays").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-weekly-days").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-monthly-options").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-monthly-week").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-monthly-week-days").classList.add("dp-control_hidden"),document.querySelector(".dp-field-scheduling-monthly-days").classList.add("dp-control_hidden"),document.getElementById("jform_scheduling")&&(document.getElementById("jform_scheduling0").checked||(document.querySelector(".dp-field-rrule").classList.remove("dp-control_hidden"),document.querySelector(".dp-field-exdates").classList.remove("dp-control_hidden"),document.querySelector(".dp-field-scheduling-end-date").classList.remove("dp-control_hidden"),document.querySelector(".dp-field-scheduling-interval").classList.remove("dp-control_hidden"),document.querySelector(".dp-field-scheduling-repeat-count").classList.remove("dp-control_hidden"),document.getElementById("jform_scheduling1").checked&&document.querySelector(".dp-field-scheduling-daily-weekdays").classList.remove("dp-control_hidden"),document.getElementById("jform_scheduling2").checked&&document.querySelector(".dp-field-scheduling-weekly-days").classList.remove("dp-control_hidden"),document.getElementById("jform_scheduling3").checked&&(document.querySelector(".dp-field-scheduling-monthly-options").classList.remove("dp-control_hidden"),document.getElementById("jform_scheduling_monthly_options0").checked?document.querySelector(".dp-field-scheduling-monthly-days").classList.remove("dp-control_hidden"):(document.querySelector(".dp-field-scheduling-monthly-week").classList.remove("dp-control_hidden"),document.querySelector(".dp-field-scheduling-monthly-week-days").classList.remove("dp-control_hidden")))))}function o(e){var t=document.querySelector(".com-dpcalendar-eventform__overlapping");t&&(t.style.display="none",loadDPAssets(["/com_dpcalendar/js/domurl/url.js"],(function(){var n=new Url;DPCalendar.request("view=event&layout=overlapping&format=json",(function(n){e.forEach((function(e){return e.disabled=!1})),n.data.message&&(t.style.display="block",t.className="com-dpcalendar-eventform__overlapping dp-info-box"+(n.data.count?"":" dp-info-box_success"),t.innerHTML=n.data.message,t.getAttribute("data-overlapping")&&e.forEach((function(e){return e.disabled=n.data.count>0})))}),DPCalendar.formToQueryString(document.querySelector(".com-dpcalendar-eventform__form"),"input:not([name=task]), select")+(n.query.e_id?"&id="+n.query.e_id:""),!0,"POST",(function(){return e.forEach((function(e){return e.disabled=!1}))}))})))}function l(){var e=document.querySelector(".com-dpcalendar-eventform .dp-map");null!=e&&(e.addEventListener("dp-map-loaded",c),[e].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)}))})));var t=document.querySelector(".com-dpcalendar-eventform .dp-field-rooms");t&&0==t.querySelectorAll("option").length&&(t.style.display="none");var n=document.querySelector(".com-dpcalendar-eventform #jform_location_lookup");if(n){loadDPAssets(["/com_dpcalendar/js/dpcalendar/layouts/block/autocomplete.js"],(function(){return DPCalendar.autocomplete.create(n)})),n.addEventListener("dp-autocomplete-select",(function(e){DPCalendar.request("task=event.newlocation",(function(e){if(null!=e.data.id&&null!=e.data.display){n.value="";var d=document.getElementById("jform_location_ids");-1==[].slice.call(d.selectedOptions).map((function(e){return e.value})).indexOf(e.data.id)&&(d.add(new Option(e.data.display,e.data.id?e.data.id:e.data.display,!1,!0)),t&&0==t.querySelectorAll("option").length&&(t.style.display="none"),d.dpInternalTrigger=!0,d.dispatchEvent(new Event("change")),d.dpInternalTrigger=!1,c())}}),"lookup="+e.detail.value+"&lookup_title="+e.detail.title)})),n.addEventListener("dp-autocomplete-change",(function(e){var t="location.searchloc";-1==window.location.href.indexOf("administrator")&&(t="locationform.searchloc"),DPCalendar.request("task="+t+"&loc="+encodeURIComponent(e.target.value.trim()),(function(e){return DPCalendar.autocomplete.setItems(n,e.data)}))}));var d=document.getElementById("jform_location_ids");d&&d.addEventListener("change",(function(e){if(!0===e.target.dpInternalTrigger||!document.getElementById("jform_rooms"))return!0;if(!isNaN(e.target.value)){var t=document.querySelector(".dp-loader");t&&t.classList.remove("dp-loader_hidden"),Joomla.submitbutton("event.reload")}}))}}function c(){var e=document.querySelector(".com-dpcalendar-eventform .dp-map");null!=e&&null!=e.dpmap&&(e.dpmap.invalidateSize&&e.dpmap.invalidateSize(),DPCalendar.Map.clearMarkers(e),[].slice.call(document.querySelectorAll("#jform_location_ids option:checked")).forEach((function(t){var n=t.innerHTML,d=n.substring(n.lastIndexOf("[")+1,n.lastIndexOf("]")).split(",");d.length<2||0==d[0]&&0==d[1]||DPCalendar.Map.createMarker(e,{latitude:d[0],longitude:d[1],title:n})})))}function a(e,t){return new Promise((function(n,d){""!==e?loadDPAssets(["/com_dpcalendar/js/tingle/tingle.js","/com_dpcalendar/css/tingle/tingle.css"],(function(){var o=new tingle.modal({footer:!0,closeMethods:[],cssClass:["dpcalendar-modal"]});o.setContent(e),o.addFooterBtn(Joomla.Text._("JYES"),"dp-button",(function(){o.close(),n(1)})),t&&o.addFooterBtn(Joomla.Text._("JNO"),"dp-button",(function(){o.close(),n(0)})),o.addFooterBtn(Joomla.Text._("JCANCEL"),"dp-button",(function(){o.close(),d()})),o.open()})):n(0)}))}document.addEventListener("DOMContentLoaded",(function(){loadDPAssets(["/com_dpcalendar/js/dpcalendar/dpcalendar.js","/com_dpcalendar/js/dpcalendar/layouts/block/select.js"],(function(){var e,c;(e=document.getElementById("jform_rrule"))&&loadDPAssets(["/com_dpcalendar/js/dayjs/dayjs.js"],(function(){e.addEventListener("change",t),document.getElementById("jform_scheduling_end_date").addEventListener("change",(function(e){e.target.classList.contains("dp-datepicker__input")&&!e.target.dpPikaday||n()})),t(),[].slice.call(document.querySelectorAll(".dp-field-scheduling, #jform_scheduling_monthly_options, #jform_scheduling_daily_weekdays")).forEach((function(e){e.addEventListener("click",(function(){d(),n()}))})),[].slice.call(document.querySelectorAll("#jform_scheduling_interval, #jform_scheduling_repeat_count,#jform_scheduling_weekly_days, #jform_scheduling_monthly_days, #jform_scheduling_monthly_week_days, #jform_scheduling_monthly_week")).forEach((function(e){e.addEventListener("change",n)}))})),function(){loadDPAssets(["/com_dpcalendar/js/dpcalendar/layouts/block/datepicker.js","/com_dpcalendar/js/dpcalendar/layouts/block/timepicker.js"]);var e=[].slice.call(document.querySelectorAll(".dp-button-apply, .button-apply, .dp-button-save, .button-save, .dp-button-save2new, .button-save-new, .dp-button-save2copy, .button-save-copy")),t=document.querySelector(".com-dpcalendar-eventform__overlapping");t&&t.getAttribute("data-overlapping")&&(document.querySelector(".dp-loader").classList.remove("dp-loader_hidden"),e.forEach((function(e){return e.disabled=!0})));var n=DPCalendar.debounce((function(){return o(e)}),2e3);[].slice.call(document.querySelectorAll("#jform_start_date, #jform_start_date_time, #jform_end_date, #jform_end_date_time, #jform_rooms")).forEach((function(e){e.addEventListener("change",n)})),document.getElementById("jform_catid")&&document.getElementById("jform_catid").addEventListener("change",n),n();var d=function(e){if(document.getElementById("jform_start_date_time")){if(e)return document.getElementById("jform_start_date_time").style.display="inline-block",void(document.getElementById("jform_end_date_time").style.display="inline-block");document.getElementById("jform_start_date_time").style.display="none",document.getElementById("jform_end_date_time").style.display="none"}};[].slice.call(document.querySelectorAll("#jform_all_day input")).forEach((function(t){t.addEventListener("click",(function(){d(0==t.value),o(e)}))}));var l=document.querySelector("#jform_all_day");l&&"input"==l.tagName.toLowerCase()?d(0==l.value):d(document.getElementById("jform_all_day0").checked||!document.getElementById("jform_all_day0").checked&&!document.getElementById("jform_all_day1").checked)}(),l(),0==parseInt(document.getElementById("jform_id").value)&&loadDPAssets(["/com_dpcalendar/js/domurl/url.js","/com_dpcalendar/js/dpcalendar/layouts/block/autocomplete.js"],(function(){var e=document.getElementById("jform_title");DPCalendar.autocomplete.create(e),e.addEventListener("dp-autocomplete-select",(function(e){document.querySelector("input[name=template_event_id]").value=e.detail.value,Joomla.submitbutton("event.reloadfromevent")}));var t=document.querySelector('.com-dpcalendar-eventform__form input[name="Itemid"]'),n=new Url;e.addEventListener("dp-autocomplete-change",(function(){loadDPAssets(["/com_dpcalendar/js/dpcalendar/dpcalendar.js"],(function(){DPCalendar.request("task=event.similar"+(t?"&Itemid="+t.value:""),(function(t){return DPCalendar.autocomplete.setItems(e,t.data)}),DPCalendar.formToQueryString(document.querySelector(".com-dpcalendar-eventform__form"),"input:not([name=task]), select")+"&id="+n.query.e_id)}))}))})),(c=document.querySelector(".dp-field-captcha"))&&document.querySelector(".com-dpcalendar-eventform__form").appendChild(c),document.getElementById("jform_catid")&&document.getElementById("jform_catid").addEventListener("change",(function(e){for(var t=0;t<e.target.length;t++)if(e.target.value&&isNaN(parseInt(e.target.options[t].value))){var n=document.querySelector(".dp-loader");return n&&n.classList.remove("dp-loader_hidden"),Joomla.submitbutton("event.reload"),!0}})),[].slice.call(document.querySelectorAll(".com-dpcalendar-eventform__actions .dp-button-action")).forEach((function(e){e.addEventListener("click",(function(){return Joomla.submitbutton("event."+e.getAttribute("data-task"))}))})),Joomla.submitbutton=function(e){var t=document.querySelector(".dp-loader");t&&t.classList.remove("dp-loader_hidden");var n=document.getElementsByName("adminForm")[0];if(n&&(-1!==e.indexOf("reload")||-1!==e.indexOf("cancel")||-1!==e.indexOf("delete")||document.formvalidator.isValid(n)))if(-1!==["save","save2new","apply"].indexOf(e.replace("event.",""))){var d=Joomla.Text._("COM_DPCALENDAR_VIEW_EVENT_FORM_UPDATE_MODIFIED","");d&&Joomla.getOptions("DPCalendar.event.form.seriesevents").forEach((function(e){d+='<p><a href="'+e.edit_link+'" target="_blank">'+e.title+" "+e.formatted_date+"</a></p>"})),document.querySelectorAll(".com-dpcalendar-eventform .dp-field_reset").length>0&&(d=Joomla.Text._("COM_DPCALENDAR_VIEW_EVENT_FORM_UPDATE_RESET","")),a(Joomla.Text._("COM_DPCALENDAR_VIEW_EVENT_SEND_TICKET_HOLDERS_NOFICATION",""),!0).then((function(e){return document.getElementById("jform_notify_changes").value=e})).then((function(){return a(d,d!==Joomla.Text._("COM_DPCALENDAR_VIEW_EVENT_FORM_UPDATE_RESET",""))})).then((function(e){return document.getElementById("jform_update_modified").value=e})).then((function(){return Joomla.submitform(e,n)})).then((function(){[].slice.call(document.querySelectorAll("#toolbar button, .com-dpcalendar-eventform__actions button")).forEach((function(e){e.disabled=!0}))})).catch((function(){var e=document.querySelector(".dp-loader");e&&e.classList.add("dp-loader_hidden")}))}else Joomla.submitform(e,n)},[].slice.call(document.querySelectorAll(".dp-field-start-date, .dp-field-end-date, .dp-field-rrule input")).forEach((function(e){e.addEventListener("change",(function(t){if(!e.closest("dp-field-start-date")&&!e.closest("dp-field-end-date")||e.dpPikaday){var n=document.querySelector(".com-dpcalendar-eventform__original-warning");n&&(n.classList.remove("com-dpcalendar-eventform__original-warning_reset"),t.target.classList.remove("dp-field_reset"),t.target.value!=t.target.defaultValue&&(n.classList.add("com-dpcalendar-eventform__original-warning_reset"),t.target.classList.add("dp-field_reset")))}}))})),[].slice.call(document.querySelectorAll(".dp-field-all-day input")).forEach((function(e){e.addEventListener("click",(function(e){var t=document.querySelector(".com-dpcalendar-eventform__original-warning");t&&(t.classList.remove("com-dpcalendar-eventform__original-warning_reset"),e.target.classList.remove("dp-field_reset"),e.target.checked&&"checked"===e.target.getAttribute("checked")||(t.classList.add("com-dpcalendar-eventform__original-warning_reset"),e.target.classList.add("dp-field_reset")))}))}))})),Joomla.Text._("COM_DPCALENDAR_ONLY_AVAILABLE_SUBSCRIBERS","")&&[].slice.call(document.querySelectorAll(".dp-field-scheduling .controls, .dp-tabs__tab-booking .controls, #com-dpcalendar-form-Content #booking .controls")).forEach((function(e){var t=document.createElement("span");t.className="dp-free-information-text",t.innerText=Joomla.Text._("COM_DPCALENDAR_ONLY_AVAILABLE_SUBSCRIBERS"),e.appendChild(t)}))}))}();