import"./categories-6f4bc6e8.js";import"./success-submit-template-c5eeef54.js";import"./header-6c55f7e3.js";import"./read-more-9fc854b8.js";import"./custom-sort.js";import"./categories-filter-82789066.js";import"./debounce.js";import"./query-params.js";(function(){var f;const _=document.querySelectorAll(".categories-aside__category"),m=document.querySelectorAll(".categories-aside__category-item"),g=window.location.pathname.split("/"),h=g[g.length-1];for(const c of m)c.addEventListener("click",r=>{if(r.preventDefault(),r.target.parentElement.className==="categories-aside__subitem")return window.location=r.target.href;if(r.target.parentElement.href)return window.location=r.target.parentElement.href;r.target.parentElement.classList.toggle("open")});for(const c of _){const r=c.parentElement;c.getAttribute("data-id")===h&&r.classList.add("active","open");const d=(f=c.nextElementSibling)==null?void 0:f.children;if(d)for(const a of d)a.getAttribute("data-id")===h&&(r.classList.add("active","open"),a.classList.add("active"))}})();(function(){const _=document.querySelector(".brands-list__functional"),m=document.querySelector(".brands-list__main"),g=document.querySelector(".brands-list__loader"),h=document.querySelector(".custom-select__button"),f=document.querySelector(".filter-button"),c=document.querySelector(".filter-block"),r=document.querySelector(".filter-button__count"),d=new URL(location),a=document.getElementById("clear-button"),L=()=>{Array.from(document.querySelectorAll(".pagination-wrapper > li > a")).forEach(e=>{d.searchParams.set("page",e.getAttribute("data-page")),e.href=d})},b=(t,e="",o,l=[])=>{const s=e||document.querySelector(".custom-select__list-item.active").getAttribute("data-value"),i=window.location.pathname.split("/"),p=i[i.length-1];g.style.display="flex",window.scrollTo({top:_.offsetTop,behavior:"smooth"});const S={sort:s,page:t,lang:o};fetch(`/categories/${p}/pagination?`+new URLSearchParams(S).toString()+l.map((n,q)=>`&star[${q}]=${n}`).join(""),{headers:{"X-Requested-With":"XMLHttpRequest"}}).then(n=>n.text()).then(n=>{m.innerHTML=n,g.style.display="none"}).then(n=>{const q=document.querySelector(".result_counter"),A=document.querySelector(".brands-result"),u=new URL(location);u.search="",t!=1&&u.searchParams.set("page",String(t)),s!=0&&s!="relevant"&&u.searchParams.set("sort",s),o.toLocaleLowerCase()!="en"&&u.searchParams.set("lang",o),l.length!=0&&(u.searchParams.delete("stars"),l.forEach((E,w)=>u.searchParams.set(`star[${w}]`,E))),history.replaceState({},"",u),L(),q.innerHTML=A.innerHTML}).catch(n=>console.error(n))};if(!m)return;m.addEventListener("click",t=>{var o;const e=t.target.closest(".pagination-wrapper a");if(e){t.preventDefault();const l=e.getAttribute("data-page"),s=document.querySelector(".custom-select__list .active").getAttribute("data-value"),i=Array.from(document.querySelectorAll('input[class="filter-rating_rate"]:checked')).map(S=>S.value),p=(o=document.querySelector(".filter-select__button"))==null?void 0:o.value;b(l,s,p,i)}}),h.addEventListener("change",t=>y(t.target.value));function y(t){var s,i;const e=Array.from(document.querySelectorAll('input[class="filter-rating_rate"]:checked')).map(p=>p.value);e.length!==0?r.innerText=` (${e.length})`:r.innerText="";const o=(s=document.querySelector(".filter-select__button"))==null?void 0:s.value,l=(i=document.querySelector(".custom-select__list-item.active"))==null?void 0:i.value;b(1,t||l,o,e)}document.querySelector(".filter-rating_stars-block").addEventListener("change",t=>{(document.querySelectorAll('input[class="filter-rating_rate"]:checked')||[]).length===0?a.classList.remove("active"):a.classList.add("active"),y()}),document.querySelector(".filter-select__list").addEventListener("click",t=>y()),a.addEventListener("click",()=>{const t=document.querySelectorAll('input[class="filter-rating_rate"]:checked');for(const e of t)e.checked=!1;a.classList.remove("active"),y()}),f.addEventListener("click",()=>{f.classList.toggle("open"),c.classList.toggle("open")}),[...Array(5).keys()].map(t=>d.searchParams.get(`star[${t}]`)).filter(t=>t!==null).forEach(t=>{const e=document.querySelector(`input[class="filter-rating_rate"][id="${t}"]`);e.checked=!0,a.classList.add("active")});const v=document.querySelector(".result_counter"),k=document.querySelector(".brands-result");v.innerHTML=k.innerHTML,L()})();
