if(!window.Joomla)throw new Error("Joomla API was not properly initialised");const initRunner=()=>{const e=Joomla.getOptions("system.paths"),o=Joomla.getOptions("com_scheduler.test-task.token"),t=`${e?`${e.base}/index.php`:window.location.pathname}?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d${o?`&${o}=1`:""}`,a=document.getElementById("scheduler-test-modal"),d=`\n    <h4 class="scheduler-headline">${Joomla.Text._("COM_SCHEDULER_TEST_RUN_TASK")}</h4>\n    <div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_STARTED")}</div>\n    <div class="mt-3 text-center"><span class="fa fa-spinner fa-spin fa-lg"></span></div>\n  `,n=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2"),r=e=>{const o=e.relatedTarget,r=parseInt(o.dataset.id,10),{title:l}=o.dataset;a.querySelector(".modal-title").innerHTML=Joomla.Text._("COM_SCHEDULER_TEST_RUN_TITLE").replace("%d",r.toString()),a.querySelector(".modal-body > div").innerHTML=d.replace("%s",l),Joomla.request({url:t.replace("%d",r.toString()),onSuccess:(e,o)=>{[].slice.call(a.querySelectorAll(".modal-body > div > div")).forEach((e=>{e.parentNode.removeChild(e)}));const t=JSON.parse(e);if(t&&t.success&&t.data){if(a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED")}</div>`,t.data.duration>0&&(a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_DURATION").replace("%s",t.data.duration.toFixed(2))}</div>`),t.data.output){const e=Joomla.sanitizeHtml(t.data.output,null,n);a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",e)}</div>`}}else a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}</div>`,a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",Joomla.Text._("JLIB_JS_AJAX_ERROR_OTHER").replace("%s",o.status))}</div>`},onError:e=>{a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}</div>`;const o=Joomla.ajaxErrorsMessages(e);a.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",o.error)}</div>`}})},l=()=>{window.location.href=`${e?`${e.base}/index.php`:window.location.pathname}?option=com_scheduler&view=tasks`};a&&(a.addEventListener("show.bs.modal",r),a.addEventListener("hidden.bs.modal",l)),document.removeEventListener("DOMContentLoaded",initRunner)};document.addEventListener("DOMContentLoaded",initRunner);