!function(){"use strict";function t(){return null!==document.getElementById("sp-ct-products")}function e(t){return sparkCt.comparisonTable.tableURL.replace("product-ids-placeholder",t.join(","))}function c(t){t=t.sort();const c=document.querySelector(".ct-sticky-col.sp-ct-col-button a");c&&(c.href=e(t))}function n(t){document.getElementById("scroll-to-top")&&(document.getElementById("scroll-to-top").style.bottom=t)}function o(){if(!t())return;f()>0?(document.getElementsByClassName("sp-ct-sticky-bar")[0].classList.remove("hidden"),setTimeout((()=>{n(document.getElementsByClassName("sp-ct-sticky-bar")[0].offsetHeight+30+"px")}),100)):(document.getElementsByClassName("sp-ct-sticky-bar")[0].classList.add("hidden"),n("30px"));const e=document.getElementsByClassName("sticky-add-to-cart");if(1===e.length&&e[0].classList.contains("sticky-add-to-cart--active")&&e[0].classList.contains("sticky-add-to-cart-bottom")){const t=document.getElementsByClassName("sticky-add-to-cart")[0].offsetHeight;document.getElementsByClassName("sp-ct-sticky-bar")[0].style.bottom=t+"px"}}function s(){t()&&(1===f()?(document.querySelector(".sp-ct-sticky-bar .sp-ct-col-button .min-prod").classList.remove("sp-ct-hide-element"),document.querySelector(".sp-ct-sticky-bar .sp-ct-col-button .sp-ct-compare-btn-wrapper").classList.add("sp-ct-hide-element")):(document.querySelector(".sp-ct-sticky-bar .sp-ct-col-button .min-prod").classList.add("sp-ct-hide-element"),document.querySelector(".sp-ct-sticky-bar .sp-ct-col-button .sp-ct-compare-btn-wrapper").classList.remove("sp-ct-hide-element")))}function r(){return i().map((t=>t.id))}function i(){const t=localStorage.getItem("nv_ct_products");return null===t?[]:JSON.parse(t)}function a(t){const e=i();for(let c=0;c<e.length;c++)e[c].id===t&&(e.splice(c,1),c--);localStorage.setItem("nv_ct_products",JSON.stringify(e))}function l(e,c,n){if(!t())return;const o=document.querySelector("#sp-ct-product-template-container").cloneNode(!0);o.querySelector("button").value=e,o.querySelector(".sp-ct-product-image-wrapper").innerHTML='<a href="'+c+'"><img src="'+n+'" /></a>',o.querySelector(".sp-ct-sticky-bar-product-container").dataset.pid=e,o.style.display="block",document.getElementById("sp-ct-products").appendChild(o)}function d(){return f()<sparkCt.comparisonTable.numberOfProductsLimit}function u(){d()?document.body.classList.remove("sp-ct-product-limit-exceed"):document.body.classList.add("sp-ct-product-limit-exceed")}function p(e){if(!t())return;const c=document.querySelector('.sp-ct-sticky-bar-product-container[data-pid="'+e+'"]');c&&c.parentNode.remove()}function m(){if(!t())return;const e=f();document.getElementsByClassName("sp-ct-sticky-bar-total-product")[0].innerHTML=e}function f(){let t=i();return t=t.filter((t=>t.id>0)),t.length}function y(t,e){let c=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n='.sp-ct-compare-btn[data-pid="'+e+'"]';"all"===e&&(n=".sp-ct-compare-btn");const o=document.querySelectorAll(n);o.forEach((n=>{c&&r().includes(e)||n.classList[t]("sp-ct-item-added")}))}window.addEventListener("load",(function(){document.body.classList.contains("sp-ct-enabled")&&(u(),function(){const t=document.getElementById("sp-ct-products");null!==t&&(t.innerHTML="");const e=i(),n=[];e.forEach((e=>{n.push(e.id),null!==t&&l(e.id,e.url,e.image),y("add",e.id)})),c(n),m(),o(),s(),u()}(),document.addEventListener("click",(function(t){const n=t.target.closest("div");if(!n||!n.classList.contains("sp-ct-compare-btn"))return;t.preventDefault();const f=n.dataset,b=f.pid,g=f.url,v=f.img;if(function(t){const e=i();for(let c=0;c<e.length;c++)if(e[c].id===t)return!0;return!1}(b))return a(b),y("remove",b),p(b),m(),o(),s(),u(),c(r()),void(document.body.classList.contains("sp-ct-comparison-table-content")&&(window.location.href=e(r())));d()&&(function(t,e,c){const n=i();n.push({id:t,url:e,image:c}),localStorage.setItem("nv_ct_products",JSON.stringify(n))}(b,g,v),y("add",b),l(b,g,v),c(r()),m(),o(),s(),u(),document.body.classList.contains("sp-ct-comparison-table-content")&&(window.location.href=e(r())))})),function(){const t=document.querySelectorAll(".sp-ct .sp-ct-remove-product");for(let c=0;c<t.length;c++)t[c].addEventListener("click",(function(t){t.preventDefault();const c=this.value;u(),a(c),window.location.href=e(r())}))}(),t()&&document.addEventListener("click",(function(t){if(t.target&&t.target.classList.contains("sp-ct-remove-product")){t.preventDefault();const e=t.target.value;a(e),p(e),m(),o(),s(),c(r()),y("remove",e),u()}})),function(){const t=document.getElementsByClassName("sp-ct-clear-all");for(let e=0;e<t.length;e++)t[e].addEventListener("click",(function(t){t.preventDefault(),localStorage.removeItem("nv_ct_products"),m(),o(),s(),document.querySelectorAll("#sp-ct-products .sp-ct-sticky-bar-product-container").forEach((t=>t.parentNode.remove())),y("remove","all")}))}())}))}();