function SearchPanel(){var container_selector=arguments.length>0&&void 0!==arguments[0]?arguments[0]:".search-panel",button_selector=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".open-search";this.container=document.querySelector(container_selector),this.button=document.querySelector(button_selector),this.open=!1,this.loader=this.container.querySelector(".search-loader"),this.input=this.container.querySelector("#search-input"),this.results=this.container.querySelector("#search-results"),this.noresult=this.container.querySelector("#no-result"),this.products=this.container.querySelector("#search-prodotti"),this.news=this.container.querySelector("#search-notizie"),this.init=function(){this.products.querySelector(".grid").innerHTML="",this.news.querySelector(".grid").innerHTML="",this.button.addEventListener("click",this.toggle),this.input.addEventListener("keyup",this.fire_search),this.input.addEventListener("change",this.fire_search),this.container.querySelector("form").addEventListener("submit",this.fire_search)},this.search=function(keyword){this.input.disabled=!0,this.loader.classList.add("visible"),this.products.classList.remove("visible"),this.news.classList.remove("visible"),this.noresult.classList.remove("visible"),doPost("/wp/wp-admin/admin-ajax.php",{action:"find",keyword:keyword},function(result){this.input.disabled=!1,this.loader.classList.remove("visible"),this.update(result)}.bind(this))},this.update=function(results){results.news.length+results.reviews.length>0?(results.news&&this.updateNews(results.news),results.reviews&&this.updateProducts(results.reviews)):this.noresult.classList.add("visible")}.bind(this),this.updateProducts=function(products){this.products.querySelector(".grid").innerHTML="",products.forEach(this.appendProduct),this.products.classList.add("visible")},this.updateNews=function(news){this.news.querySelector(".grid").innerHTML="",news.forEach(this.appendNews),this.news.classList.add("visible")},this.appendProduct=function(product){var content=' \t\t
\t\t';content=(content=(content=(content=content.replace(/__item.link__/g,product.link)).replace(/__item.title__/g,product.title)).replace(/__item.image__/g,product.img)).replace(/__item.label__/g,product.category?product.category:""),this.products.querySelector(".grid").insertAdjacentHTML("beforeend",content)}.bind(this),this.appendNews=function(news){var content=' \t\t \t\t';content=(content=(content=(content=content.replace(/__item.link__/g,news.link)).replace(/__item.title__/g,news.title)).replace(/__item.image__/g,news.img)).replace(/__item.label__/g,news.category?news.category:""),this.news.querySelector(".grid").insertAdjacentHTML("beforeend",content)}.bind(this),this.open=function(){this.container.classList.add("open")}.bind(this),this.close=function(){this.container.classList.remove("open")}.bind(this),this.wait_to_fire=null,this.fire_search=function(event){event.preventDefault(),event.stopPropagation(),null!=this.wait_to_fire&&clearInterval(this.wait_to_fire),this.input.value.length>2&&(this.wait_to_fire=setInterval(function(){this.search(this.input.value),clearInterval(this.wait_to_fire)}.bind(this),800))}.bind(this),this.init()}