document.addEventListener("DOMContentLoaded",function(){var t=document.querySelector("#select_category"),o=document.querySelector("#search_template"),e=document.querySelector(".search_favorite");function a(){var n=t.value,s=o.value.toLowerCase(),a=document.querySelectorAll("a.search_favorite.active").length,e=document.querySelectorAll(".ts-item:not(.ignore)"),c=0;e.forEach(function(e){var t=!0;n&&e.dataset.cat!=n&&(t=!1),s&&(e.dataset.title.toLowerCase().includes(s)||(t=!1));if(a){var o=e.querySelector(".favorite_icon");o&&(!o||e.querySelector(".favorite_icon").classList.contains("active"))||(t=!1)}t?(c++,e.style.display="block"):e.style.display="none"}),0<c?(document.querySelector(".ts-list").style.display="flex",document.querySelector(".ts-no-results").style.display="none"):(document.querySelector(".ts-list").style.display="none",document.querySelector(".ts-no-results").style.display="block")}o.addEventListener("keyup",function(){0<this.value.length&&this.value.length<3||a()}),t.addEventListener("change",function(){a()}),e.addEventListener("click",function(){e.classList.toggle("active"),a()}),document.querySelectorAll(".ts-item").forEach(function(e){e.addEventListener("click",function(e){e.target.classList.contains("favorite_icon")&&(e.preventDefault(),function(n){var e=Joomla.getOptions("csrf.token"),t=Joomla.getOptions("system.paths").base,o="/index.php?option=com_rstbox&view=templates&format=json&layout=raw&task=favorites_toggle&template_id="+n+"&"+e+"=1",s=new XMLHttpRequest;s.open("POST",t+o),s.onload=function(){if(200<=s.status&&s.status<300){var e=JSON.parse(s.response),t=Object.keys(e).includes(n),o=document.querySelector(".ts-item[data-id='"+n+"'] .favorite_icon");if(t)o.classList.add("active");else o.classList.remove("active"),document.querySelectorAll("a.search_favorite.active").length&&a()}},s.send()}(e.target.closest(".ts-item").dataset.id))})}),null!==document.querySelector(".licenseInvalid")&&document.addEventListener("click",function(e){if(e.target.classList.contains("ts-preview"))return alert(Joomla.Text._("COM_ENGAGEBOX_GALLERY_DOWNLOAD_KEY")),e.preventDefault(),!1})});

