(()=>{"use strict";var t={};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}();const e={interval:250,maxWait:8e3,available(t,s=e.interval,r=e.maxWait){return new Promise(((e,o)=>{const i=window.setInterval((()=>{if(this.findVarByName(t))return e(),clearTimeout(l),void clearInterval(i)}),s),l=window.setTimeout((function(){clearTimeout(i),o()}),r)}))},findVarByName(t){let e=0,s=t.split("."),r=window;try{for(;null!=r&&et.indexOf(s)&&t.push(s)})),t.length?("number"==typeof commerceLoadDelay&&(r.priceUpdateDelay=commerceLoadDelay),setTimeout(r.fetchPricesBatch,r.priceUpdateDelay,t)):this.enablePriceFiltering()},fetchPricesBatch(e){if(0===e.length)return;const s=e.splice(0,this.fetchLimit),o="/wp-json/heavy/v1/amazon-product-data/?id="+encodeURIComponent(s.join(","));fetch(o,{headers:{"X-WP-Nonce":t.g.heavyCommercePriceRefreshNonce.nonce},method:"POST"}).then((t=>t.json())).then((t=>{r.updatePrices(t),setTimeout((()=>{r.fetchPricesBatch(e)}),r.fetchInterval)}))},updatePrices(t){Object.keys(t).forEach((function(e){const s=t[e].price,r=t[e].formatted_price,o=t[e].asin,i=document.querySelectorAll('.js-product[data-product-id="'+e+'"]');i&&(s&&r?Array.prototype.forEach.call(i,(function(t){t.dataset.amount=s;const e=t.querySelectorAll(".js-dynamic-price");Array.prototype.forEach.call(e,(function(t){t.textContent=r})),t.classList.remove("is-stale")})):o&&Array.prototype.forEach.call(i,(function(t){t.remove()})))})),this.enablePriceFiltering()},getProducts:()=>[...document.querySelectorAll(".l-products-grid__list .js-product")],getPrices(){return this.getProducts().map((t=>parseFloat(t.dataset.amount)))},getPricesRange(){const t=this.getPrices();return{min:Math.min(...t.filter((t=>t))),max:Math.max(...t)}},setPriceLabel(t,e){const s=document.querySelector(`.js-product-price-${t}`);if(null===s)return;const r=e/this.decimals;s.textContent="min"===t?Math.floor(r):Math.ceil(r)},setCountLabel(t){const e=document.querySelector(".js-product-count");null!==e&&(e.textContent=t)},enablePriceFiltering(){const t=document.querySelector(".js-product-slider"),e=s.available("noUiSlider",200,15e3),r=document.querySelector(".l-products-grid__header");null!==t&&void 0===t.noUiSlider&&e.then((()=>{const{min:e,max:s}=this.getPricesRange();this.setPriceLabel("min",e),this.setPriceLabel("max",s);const o=noUiSlider.create(t,{start:[e,s],connect:!0,margin:1e3,step:this.decimals,tooltips:!1,range:{min:e,max:s}});r.classList.add("is-initialised"),o.on("update",(t=>this.onSliderUpdate(t)))}))},onSliderUpdate([t,e]){const s=this.getProducts(),r=s.filter((s=>{const r=parseFloat(s.dataset.amount);return s.classList.contains("post-sponsored")||r>=t&&r<=e}));s.map((t=>{-1===r.indexOf(t)?t.classList.add("is-out-of-range"):t.classList.remove("is-out-of-range")})),s.map((t=>{0===Number(t.dataset.amount)&&(s.length!==r.length?t.classList.add("is-out-of-range"):t.classList.remove("is-out-of-range"))})),this.setPriceLabel("min",t),this.setPriceLabel("max",e),this.setCountLabel(r.length),document.querySelector(".js-sortable").dispatchEvent(new Event("update"))}},o=r,i={lazySelector:"[data-lazy-load]",html:{},init(t){let e=s.available("IOlazy");t&&(i.lazySelector=t),e.then(i.go).catch(i.basicLazyLoad)},go(){i.html=document.querySelector("html"),i.html.classList.remove("no-js"),new IOlazy({image:i.lazySelector,rootMargin:parseInt(2*window.innerHeight,10)+"px 0px"})},basicLazyLoad(){[].forEach.call(document.querySelectorAll(this.lazySelector),(function(t){t.getAttribute("data-src")&&t.setAttribute("src",t.getAttribute("data-src")),t.getAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset")),t.onload=function(){t.removeAttribute("data-src"),t.removeAttribute("data-srcset"),t.removeAttribute("data-lazy-load")}}))}},l=i,a={sortables:[],hasSponsored:!1,sponsoredPosition:2,sortablesWrapper:null,buttons:[],init(){this.buttons=[...document.querySelectorAll(".js-sort")],0!==this.buttons.length&&(this.sortablesWrapper=document.querySelector(".js-sortable"),this.sortables=[...this.sortablesWrapper.children].filter((t=>"0"!==String(t.dataset.amount)||(t.classList.add("hidden"),!1))),this.hasSponsored=null!==this.sortablesWrapper.querySelector(".post-sponsored"),this.buttons.map((t=>t.addEventListener("click",(t=>this.onButtonClick(t))))),this.setupInitialState())},onButtonClick(t){const e=t.target;if(e.classList.contains("is-active"))return;if(!e.dataset.order)return;t.preventDefault();const{order:s}=e.dataset;this.reorder(s),this.setActiveButton(e),l.basicLazyLoad()},setupInitialState(){const t=this.getQueryParam("sort");if(null===t)return;this.reorder(t);const e=this.getFilterButton(t);e&&this.setActiveButton(e),this.scrollIntoView()},setActiveButton(t){const e=this.getActiveButton();null!==e&&e.classList.remove("is-active"),t.classList.add("is-active")},getFilterButton(t){return this.buttons.find((e=>e.dataset.order&&t===e.dataset.order))},getActiveButton(){return this.buttons.find((t=>t.classList.contains("is-active")))},scrollIntoView(){const t=document.querySelector(".l-header"),e=null===t?0:t.offsetHeight,s=this.sortablesWrapper.parentElement.offsetTop;window.scroll({top:s-e,left:0,behavior:"smooth"})},getQueryParam(t){if(null===document.location.search)return null;const e=document.location.search.slice(1).split("&").map((t=>{const[e,s]=t.split("=");return{key:e,value:s}})).find((e=>t===e.key));return e?e.value:null},reorder(t){if(this.sortablesWrapper.dispatchEvent(new Event("update")),"asc"===t?this.sortables.sort(this.sortByPrice):"desc"===t?(this.sortables.sort(this.sortByPrice),this.sortables.reverse()):this.sortables.sort(this.sortByOrder),this.hasSponsored){const t=this.sortables.findIndex((t=>t.classList.contains("post-sponsored"))),e=this.sortables[t];this.sortables.splice(t,1),this.sortables.splice(this.sponsoredPosition,0,e)}let e=document.createDocumentFragment();for(this.sortables.forEach((t=>{e.appendChild(t.cloneNode(!0))}));this.sortablesWrapper.firstChild;)this.sortablesWrapper.removeChild(this.sortablesWrapper.firstChild);this.sortablesWrapper.appendChild(e)},sortByPrice:(t,e)=>t.dataset.amount===e.dataset.amount?0:parseInt(t.dataset.amount,10)t.dataset.order-e.dataset.order},n={currentItem:null,placeholder:null,placeholderIndex:null,scrollPosition:0,productDetailsTemplate:null,init(){const t=this.getListElement();null!==t&&(this.productDetailsTemplate=document.getElementById("tmpl-product-card--details"),this.productDetailsTemplate&&(this.productDetailsTemplate=this.productDetailsTemplate.content.firstElementChild),t.addEventListener("update",(()=>{null!==this.currentItem&&this.onItemClick(this.currentItem)})),t.addEventListener("click",(t=>{if(null===t.target.closest("[data-products-grid-item-toggle]"))return;t.preventDefault();const e=t.target.closest("[data-products-grid-item]");null!==e&&this.onItemClick(e)})))},getListElement:()=>document.querySelector(".js-sortable"),getVisibleItems:()=>[...document.querySelectorAll("[data-products-grid-item]:not( .is-out-of-range )")].filter((t=>"none"!==window.getComputedStyle(t).display)),onItemClick(t){if(t===this.currentItem)return this.currentItem=null,this.collapseItem(t),this.enableMobileScroll(),void this.collapsePlaceholder();null!==this.currentItem&&this.collapseItem(this.currentItem),this.currentItem=t,this.appendProductDetailsElement(this.currentItem),this.expandItem(this.currentItem),this.disableMobileScroll(),this.repositionDetails(),this.togglePlaceholder()},expandItem(t){t.classList.add("is-expanded")},collapseItem(t){t.classList.remove("is-expanded"),t.className=t.className.replace(/is\-position\-\d+/gi,"")},repositionDetails(){const t=this.getVisibleItems().indexOf(this.currentItem)%this.getNumberOfItemsInRow();this.currentItem.classList.add(`is-position-${t+1}`)},disableMobileScroll(){this.scrollPosition=window.pageYOffset,document.body.classList.add("is-mobile-scroll-disabled")},enableMobileScroll(){document.body.classList.remove("is-mobile-scroll-disabled"),window.scrollTo(0,this.scrollPosition)},togglePlaceholder(){const t=this.getVisibleItems(),e=this.getNumberOfItemsInRow();if(2>=e)return void this.collapsePlaceholder();let s=this.getCurrentItemRowIndex()*e+e-1;s>=t.length&&(s=t.length-1),s!==this.placeholderIndex&&(this.collapsePlaceholder(),this.placeholderIndex=s,this.placeholder=this.getPlaceholderElement(),t[s].insertAdjacentElement("afterEnd",this.placeholder));const r=this.currentItem.querySelector("[data-products-grid-item-details]").offsetHeight;this.placeholder.style.height=`${r}px`,this.scrollIntoView()},scrollIntoView(){const t=document.querySelector(".l-header"),e=null===t?0:t.offsetHeight,s=.6*this.currentItem.offsetHeight,r=this.getListElement().offsetTop+this.currentItem.offsetTop+s;window.scroll({top:r-e,left:0,behavior:"smooth"})},collapsePlaceholder(){const t=this.placeholder;null!==t&&t.remove(),this.placeholder=null,this.placeholderIndex=null},getPlaceholderElement(){const t=document.createElement("li");return t.classList.add("is-placeholder"),t},getCurrentItemRowIndex(){const t=this.getNumberOfItemsInRow(),e=this.getVisibleItems().indexOf(this.currentItem);return Math.floor(e/t)},getNumberOfItemsInRow(){const t=this.getVisibleItems();return Math.round(this.getListElement().offsetWidth/t[0].offsetWidth)},appendProductDetailsElement(t){const e=t.querySelector(".l-products-grid__item-details");if(!e||0{t.href=r.trim(),t.target="_blank",t.rel="nofollow noopener noreferrer"}));const o=t.querySelector(".c-product-card__title").textContent;[...s.querySelectorAll(".c-product-card__title a")].forEach((t=>{t.textContent=o}));const i=t.querySelector(".js-dynamic-price").textContent;[...s.querySelectorAll(".js-dynamic-price")].forEach((t=>{t.textContent=i}));const l=void 0!==t.dataset.isAmazon;[...s.querySelectorAll(".js-show-if-amazon")].forEach((t=>{l?t.removeAttribute("hidden"):t.setAttribute("hidden","hidden")}));const{shopLinkLabel:a}=t.dataset;[...s.querySelectorAll(".js-shop-link-label")].forEach((t=>{t.textContent=a}));const n=t.querySelector(".c-product-card__video-frame"),c=t.querySelector(".c-product-card__image-frame img");if(n){const t=n.cloneNode(!0),e=t.querySelector("iframe");e&&(void 0===e.dataset.src?e.setAttribute("src",e.getAttribute("src")):e.setAttribute("src",e.dataset.src)),s.querySelector(".c-product-card__image").append(t)}else if(c){const t=c.cloneNode(!0);t.dataset.src&&(t.setAttribute("src",t.dataset.src),delete t.dataset.src,delete t.dataset.lazyLoad),s.querySelector(".c-product-card__image-frame").append(t)}const d=t.querySelector(".c-content");d&&(s.querySelector(".c-product-card__content").append(d),d.removeAttribute("hidden")),e.append(s)}};function c(){n.init(),o.init(),a.init()}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c):c()})();