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

${Joomla.Text._("COM_SCHEDULER_TEST_RUN_TASK")}

\n
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_STARTED")}
\n
\n `,n=e=>e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1
$2");a.addEventListener("show.bs.modal",(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+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED")}
`,t.data.duration>0&&(a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_DURATION").replace("%s",t.data.duration.toFixed(2))}
`),t.data.output){const e=Joomla.sanitizeHtml(t.data.output,null,n);a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",e)}
`}}else a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}
`,a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",Joomla.Text._("JLIB_JS_AJAX_ERROR_OTHER").replace("%s",o.status))}
`},onError:e=>{a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}
`;const o=Joomla.ajaxErrorsMessages(e);a.querySelector(".modal-body > div").innerHTML+=`
${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",o.error)}
`}})})),a.addEventListener("hidden.bs.modal",(()=>{window.location.href=`${e?`${e.base}/index.php`:window.location.pathname}?option=com_scheduler&view=tasks`})),document.removeEventListener("DOMContentLoaded",initRunner)};document.addEventListener("DOMContentLoaded",initRunner);