(()=>{"use strict";var e={n:t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},d:(t,i)=>{for(var a in i)e.o(i,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:i[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.apiFetch;var i=e.n(t);function a(e,t){return new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className)}function n(e){var t,i=1,n=null===(t=e.closest(".ebproductgrid-pagination"))||void 0===t?void 0:t.querySelector(".ebpg-pagination-item.active");if(n){if(i=n.dataset?n.dataset.pagenumber:1,a(e,"ebpg-pagination-item-next")){for(var r=n.nextElementSibling;r&&!r.classList.contains("ebpg-pagination-item");)r=r.nextElementSibling;r.classList.add("active"),n.classList.remove("active")}else if(a(e,"ebpg-pagination-item-previous")){for(var s=n.previousElementSibling;s&&!s.classList.contains("ebpg-pagination-item");)s=s.previousElementSibling;s.classList.add("active"),n.classList.remove("active")}o(e.closest(".ebproductgrid-pagination"))}return i}function o(e){var t=e.querySelector(".ebpg-pagination-item.active");if(t){var i=parseInt(t.dataset.pagenumber),a=e.querySelectorAll(".ebpg-pagination-item"),n=a.length,o=1;a.forEach(function(e){o=parseInt(e.dataset.pagenumber),function(e){e.classList.remove("show"),e.classList.add("hide")}(e),(1===i&&o<=3||o>=i&&o<=i+2||o===n||1===o&&(i>=n-2||i>=4))&&function(e){e.classList.remove("hide"),e.classList.add("show")}(e)});var r=e.querySelectorAll(".ebpg-pagination-item-separator");r.length>0&&r.forEach(function(e){e.remove()});var s='<button class="ebpg-pagination-item-separator">...</button>';i<a.length-2&&a[a.length-1].insertAdjacentHTML("beforebegin",s),(i>=n-2||n>4&&i>=4)&&a[1].insertAdjacentHTML("afterend",s),1===i?(e.querySelector(".ebpg-pagination-item-previous").disabled=!0,e.querySelector(".ebpg-pagination-item-next").disabled=!1):i===n?(e.querySelector(".ebpg-pagination-item-previous").disabled=!1,e.querySelector(".ebpg-pagination-item-next").disabled=!0):(e.querySelector(".ebpg-pagination-item-previous").disabled=!1,e.querySelector(".ebpg-pagination-item-next").disabled=!1)}}document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll(".eb-woo-products-wrapper");if(e)for(var t=0;t<e.length;t++){var r=e[t].querySelector(".ebproductgrid-pagination");if(r){var s=r.querySelectorAll(".ebpg-pagination button");s.length>0&&(document.querySelectorAll(".ebproductgrid-pagination").forEach(function(e){o(e)}),s.forEach(function(e){var t=1;e.addEventListener("click",function(){var e=this,r=a(this,"ebpg-pagination-button"),s=a(this,"ebpg-pagination-item-previous"),c=a(this,"ebpg-pagination-item-next");t=r?parseInt(t)+1:s?parseInt(n(this))-1:c?parseInt(n(this))+1:parseInt(this.dataset.pagenumber);var p=this.closest(".eb-woo-products-wrapper");if(p){var l=p.dataset;i()({path:"essential-blocks/v1/products?query_data=".concat(encodeURIComponent(l.querydata),"&attributes=").concat(encodeURIComponent(l.attributes),"&pageNumber=").concat(t,"&is_frontend=true")}).then(function(t){r?t?e.closest(".ebproductgrid-pagination").parentElement.querySelector(".eb-woo-products-gallery").insertAdjacentHTML("beforeend",t):(e.closest(".ebproductgrid-pagination").insertAdjacentHTML("beforebegin",'<p class="eb-no-posts">No more products</p>'),e.closest(".ebproductgrid-pagination").remove()):(e.closest(".eb-woo-products-wrapper").querySelectorAll(".eb-woo-products-col").forEach(function(e){e.remove()}),e.closest(".ebproductgrid-pagination").parentElement.querySelector(".eb-woo-products-gallery").insertAdjacentHTML("beforeend",t),a(e,"ebpg-pagination-item")&&(e.closest(".ebproductgrid-pagination").querySelectorAll(".ebpg-pagination-item").forEach(function(e){e.classList.remove("active")}),e.classList.add("active")),o(e.closest(".ebproductgrid-pagination")))})}})}))}}})})();