/**
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */((s,n)=>{if(!s)throw new Error("core.js was not properly initialised");s.finderIndexer=()=>{let g,c=null,E=null,d=null,p=!1;const _="index.php?option=com_finder&tmpl=component&format=json",R=`&${n.getElementById("finder-indexer-token").getAttribute("name")}=1`,o=e=>{const i=n.getElementById(e);return i?i.parentNode.removeChild(i):null},h=(e,i)=>{d=E/c*100;const r=n.getElementById("progress-bar"),t=n.getElementById("finder-progress-header"),a=n.getElementById("finder-progress-message");t&&(t.innerText=e),a&&(a.innerHTML=s.sanitizeHtml(i)),r&&(d<100?(r.style.width=`${d}%`,r.setAttribute("aria-valuenow",d)):(r.classList.remove("bar-success"),r.classList.add("bar-warning"),r.setAttribute("aria-valuemin",100),r.setAttribute("aria-valuemax",200),r.style.width=`${d}%`,r.setAttribute("aria-valuenow",d)),i===s.Text._("COM_FINDER_INDEXER_MESSAGE_COMPLETE")&&(o("progress"),window.parent.location.reload()))},I=(e,i)=>{const r=n.getElementById("finder-progress-header"),t=n.getElementById("finder-progress-message");try{if(e===null)throw new Error(i);if(e.error)throw new Error(e);if(e.start&&(c=e.totalItems,n.getElementById("finder-debug-data"))){const a=n.getElementById("finder-debug-data");Object.entries(e.pluginState).forEach(f=>{let l=`<dt class="col-sm-3">${f[0]}</dt>`;l+=`<dd id="finder-${f[0].replace(/\s+/g,"-").toLowerCase()}" class="col-sm-9"></dd>`,a.insertAdjacentHTML("beforeend",s.sanitizeHtml(l,{dd:["class","id"],dt:["class"]}))})}E+=e.batchOffset,h(e.header,e.message),n.getElementById("finder-debug-data")&&Object.entries(e.pluginState).forEach(a=>{n.getElementById(`finder-${a[0].replace(/\s+/g,"-").toLowerCase()}`).innerHTML=s.sanitizeHtml(`${e.pluginState[a[0]].offset} of ${e.pluginState[a[0]].total}`)}),E<c?g("indexer.batch"):p||(p=!0,g("indexer.optimize"))}catch(a){o("progress");try{e.error&&(r&&(r.innerText=e.header,r.classList.add("finder-error")),t&&(t.innerHTML=s.sanitizeHtml(e.message),t.classList.add("finder-error")))}catch{a===""&&(a=s.Text._("COM_FINDER_NO_ERROR_RETURNED")),r&&(r.innerText=s.Text._("COM_FINDER_AN_ERROR_HAS_OCCURRED"),r.classList.add("finder-error")),t&&(t.innerHTML=s.sanitizeHtml(a),t.classList.add("finder-error"))}}return!0},T=e=>{const i=n.getElementById("finder-progress-header"),r=n.getElementById("finder-progress-message");let t;if(e instanceof Error){const l=n.createElement("div");l.textContent=e.message,t=l.innerHTML,e instanceof SyntaxError&&(t=s.Text._("JLIB_JS_AJAX_ERROR_PARSE").replace("%s",t))}else if(typeof e=="object"&&e.responseText){t=e.responseText;try{t=JSON.parse(t)}catch{t=s.Text._("JLIB_JS_AJAX_ERROR_OTHER").replace("%s",e.status)}}o("progress");const a=t&&t.header?t.header:s.Text._("COM_FINDER_AN_ERROR_HAS_OCCURRED"),f=t&&t.message?t.message:`${s.Text._("COM_FINDER_MESSAGE_RETURNED")}<br>${t}`;i&&(i.innerText=a,i.classList.add("finder-error")),r&&(r.innerHTML=s.sanitizeHtml(f),r.classList.add("finder-error"))};g=e=>{s.request({url:`${_}&task=${e}${R}`,promise:!0}).then(i=>{I(JSON.parse(i.responseText))}).catch(i=>{T(i)})},E=0,d=0,g("indexer.start")}})(Joomla,document),document.addEventListener("DOMContentLoaded",()=>{window.Indexer=Joomla.finderIndexer()});
