!function(){"use strict";const t="data-badge",e="[data-wishlist-counter]";function n(n){const i=document.querySelector(e);if(!i)return;const o=parseInt(i.getAttribute(t)||"0",10);i.setAttribute(t,(o+n).toString())}const i={"Content-Type":"application/json"};function o(){return window.__javascriptExtraGlobals__.metafields.backend_api_host}function c(){const{id:t,email:e}=window.__javascriptExtraGlobals__.customer;return{customer_id:t,customer_email:e}}function s(){return!!window.__javascriptExtraGlobals__.customer.id}const r="singularuWishlistItems";function a(){return JSON.parse(localStorage.getItem(r)||"[]")}function d(){return document.querySelectorAll("[data-add-to-wishlist]")}async function u(t){d().forEach((e=>{const n=null==e?void 0:e.getAttribute("data-product-id");e&&n&&t.includes(+n)&&e.classList.add("active")}))}function l(t){const e=t.target,d=null==e?void 0:e.getAttribute("data-product-id");var u;e&&d&&(t.preventDefault(),t.stopPropagation(),e.classList.contains("active")?function(t){return s()?function(t){const e=o();return fetch("".concat(e,"theme/wishlist_items/").concat(t),{method:"DELETE",headers:i,body:JSON.stringify(c())})}(t).then((t=>Promise.resolve(t.ok))):(function(t){const e=a(),n=e.indexOf(t);n>-1&&(e.splice(n,1),localStorage.setItem(r,JSON.stringify(e)))}(t),Promise.resolve(!0))}(+d).then((t=>{t&&(e.classList.remove("active"),n(-1))})):((u=[+d],s()?function(t){const e=o();return fetch("".concat(e,"theme/wishlist_items"),{method:"POST",headers:i,body:JSON.stringify({product_id:t,...c()})})}(u).then((t=>Promise.resolve(t.ok))):(function(t){let e=a();e=e.concat(t),e=e.filter(((t,n)=>e.indexOf(t)===n)),localStorage.setItem(r,JSON.stringify(e))}(u),Promise.resolve(!0))).then((t=>{t&&(e.classList.add("active"),n(1))})),function(){let t={};window.item&&(t={ProductID:window.item.ProductID,ProductName:window.item.Name,URL:window.item.URL,Price:window.item.Price,ImageURL:window.item.ImageURL}),window._learnq&&window._learnq.track("Added to Wishlist",{...t})}()))}function m(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e=d();e.forEach((e=>{t&&e.removeEventListener("click",l),e.addEventListener("click",l)}))}document.addEventListener("DOMContentLoaded",(async function(){const n=await(s()?function(){const t=c(),e=new URLSearchParams(t),n=o();return fetch("".concat(n,"theme/wishlist_items?").concat(e.toString()),{method:"GET",headers:i})}().then((t=>t.json())).then((t=>t.map((t=>parseInt(t,10))))):Promise.resolve(a()));!function(n){const i=document.querySelector(e);i&&i.setAttribute(t,n.length.toString())}(n),u(n),m(),document.addEventListener("ajaxinate",(function(){u(n),m(!0)}))}))}();