"use strict";(()=>{document.addEventListener("DOMContentLoaded",function(){let S=document.querySelector('[fs-cmssort-field="popularity-desc"]');S&&S.click();let k=document.querySelector('[fs-cmssort-element="trigger"]');k&&(k.dispatchEvent(new Event("w-close")),window.scrollTo(0,0));function $(o){let s=o.textContent.trim().match(/(\d+(?:\.\d+)?)\s*mb/i);return s?parseFloat(s[1]):null}function G(o){let s=o.textContent.trim().match(/^(\d[\d\s]*)\s?szt\.$/);return s?parseFloat(s[1].replace(/\s+/g,"")):null}function V(o){return o.toString().replace(/\B(?=(\d{3})+(?!\d))/g," ")}function A(o){let a=parseFloat(o.textContent.trim());if(!isNaN(a)){let s=a*10;return o.textContent=`${s}mm`,s}return null}function H(o,a){let s=a.textContent.trim();if(o.querySelectorAll('option[fs-cmsfilter-field="D\u0142ugo\u015B\u0107"]').length>0)return!0;let E=s.match(/(\d+(?:,\d+)?)\s*mb/);if(E){let g=E[1],d=document.createElement("div");return d.setAttribute("fs-cmsfilter-field","D\u0142ugo\u015B\u0107"),d.textContent=`${g}mb`,d.classList.add("hide"),o.appendChild(d),g}return console.warn("\u26A0\uFE0F Produkt nie ma d\u0142ugo\u015Bci w nazwie"),null}window.fsAttributes=window.fsAttributes||[],window.fsAttributes.push(["cmsload",async o=>{let[a]=o;async function s(){try{let y=function(t,e,r=!0){let h=document.createElement("div");h.className="filters3_item";let l=document.createElement("label");l.className="w-checkbox filters3_form-checkbox1";let f=document.createElement("div");f.className="w-checkbox-input w-checkbox-input--inputType-custom filters3_form-checkbox1-icon";let c=document.createElement("input");c.type="checkbox",c.name="filter",c.style="opacity:0;position:absolute;z-index:-1";let i=document.createElement("span");i.className="filters3_form-checkbox1-label w-form-label",i.textContent=r?`${e==="Ilo\u015B\u0107"?V(t):t}${e==="D\u0142ugo\u015B\u0107"?"mb":e==="Ilo\u015B\u0107"?" szt.":"mm"}`:`${t}`,i.setAttribute("fs-cmsfilter-field",e);let m=document.createElement("span");return m.className="filter-results-count",m.style="margin-left: 10px; font-weight: bold;",m.textContent="0",l.appendChild(f),l.appendChild(c),l.appendChild(i),l.appendChild(m),h.appendChild(l),h};var w=y;await a.renderingQueue;let E=await a.items,g=new Set,d=new Set,I=new Set,q=new Set,M=new Set;E.forEach((t,e)=>{if(!t||!t.element){console.error(`\u274C B\u0142\u0105d: item.element nie istnieje dla indeksu ${e}`,t);return}let r=t.element.querySelector('[fs-cmsfilter-field="Cena"]');if(r){let n=r.textContent?.replace(/\s/g,"").replace("z\u0142","").replace(",",".").trim(),u=parseFloat(n||"");isNaN(u)?console.warn("\u274C Nie uda\u0142o si\u0119 sparsowa\u0107 ceny:",r.textContent):r.textContent=u.toFixed(2)}t.element.querySelectorAll('[is-variant-select="true"]').forEach((n,u)=>{let B=n.closest('[role="group"]');if(B){let T=B.querySelector("label");if(T?.textContent){let b=T.textContent.trim();if(b==="MIX"){let C=n.closest(".product2_item");if(C){let _=C.querySelector('[fs-cmsfilter-field="Grubo\u015B\u0107"]');_&&(_.textContent="MIX")}}n.querySelectorAll("option").forEach(C=>{b==="D\u0142ugo\u015B\u0107"?C.setAttribute("fs-cmsfilter-field","D\u0142ugo\u015B\u0107"):(b==="Komplet"||b==="MIX")&&C.setAttribute("fs-cmsfilter-field","Ilo\u015B\u0107")})}}});let l=t.element.querySelector('[fs-cmsfilter-field="nazwa"]');if(l&&l.textContent?.includes("MIX")){let n=t.element.querySelector('[fs-cmsfilter-field="Grubo\u015B\u0107"]');n&&(n.textContent="MIX")}let f=t.element.querySelector('[fs-cmsfilter-field="Grubo\u015B\u0107"]'),c=t.element.querySelector('[fs-cmsfilter-field="Szeroko\u015B\u0107"]'),i=t.element.querySelector('[fs-cmsfilter-field="Kolor"]'),m=t.element.querySelectorAll('[fs-cmsfilter-field="Ilo\u015B\u0107"]'),z=t.element.querySelectorAll('option[fs-cmsfilter-field="D\u0142ugo\u015B\u0107"]'),x=f?.textContent==="MIX",p=H(t.element,l);if(p!==!0&&p!==null&&I.add(p),f)if(x)g.add("MIX");else{let n=A(f);n!==null&&g.add(n)}if(c){let n=A(c);n!==null&&d.add(n)}i&&i.textContent!==""&&M.add(i.textContent),z.forEach(n=>{let u=$(n);u!==null&&I.add(u.toString())}),m.forEach(n=>{let u=G(n);u!==null&&q.add(u)})});let L=document.getElementById("lista-grubosc");L?Array.from(g).sort((t,e)=>t==="MIX"?-1:e==="MIX"?1:t-e).forEach(t=>{let r=y(t,"Grubo\u015B\u0107",t!=="MIX");L.appendChild(r)}):console.error("Element #lista-grubosc not found");let v=document.getElementById("lista-szerokosc");v?Array.from(d).sort((t,e)=>t-e).forEach(t=>{let e=y(t,"Szeroko\u015B\u0107");v.appendChild(e)}):console.error("Element #lista-szerokosc not found");let N=document.getElementById("lista-kolor");N?Array.from(M).sort((t,e)=>t-e).forEach(t=>{let e=y(t,"Kolor",!1);N.appendChild(e)}):console.error("Element #lista-kolor not found");let D=document.getElementById("lista-dlugosc");D?Array.from(I).sort((t,e)=>t-e).forEach(t=>{let e=y(t,"D\u0142ugo\u015B\u0107",!0);D.appendChild(e)}):console.error("Element #lista-dlugosc not found");let X=document.getElementById("lista-ilosc");X?Array.from(q).sort((t,e)=>t-e).forEach(t=>{let e=y(t,"Ilo\u015B\u0107",!0);X.appendChild(e)}):console.error("Element #lista-ilosc not found"),window.fsAttributes.cmsfilter.init(),window.fsAttributes.push(["cmsfilter",t=>{let[e]=t,{filtersData:r}=e;function h(){console.log("filtersData:",r),r.forEach(function(l){let{elements:f}=l;f.forEach(function(c){let i=c.value,m=c.resultsCount;Array.from(document.querySelectorAll("[fs-cmsfilter-field]")).filter(function(x){return x.textContent.trim().includes(i)}).forEach(function(x){let p=x.nextElementSibling;p&&p.classList.contains("filter-results-count")&&(p.textContent=m)})})})}h(),e.listInstance.on("renderitems",()=>{h()})}])}catch(E){console.error("Error during CMS load handling:",E)}}await s()}])});})();