'));let r=document.getElementsByClassName("wpn-choose-gift-label-container");r.length>0&&Array.from(r).forEach(e=>{e.style.zIndex="new_linkedman"===LS.theme.code||"Simple"===LS.theme.name?1040:1080})}}function L(){let e=sessionStorage.getItem("wpn_last_variant_added"),t=!1;if(null!==e){t=null!==K(e)}return t}async function C(){const e=await d();if(w()&&e){let t=e.crossItems;Object.keys(t).length>0&&function(e){let t=document.querySelector('[data-store="product-price-'+LS.product.id+'"]');if(null!==t){let n=0,o=document.createElement("span");o.id="wpn-show-cross-items-discounts",o.style.cursor="pointer";let r=h("More discounts");o.innerHTML=r+' ',o.addEventListener("click",(function(){let e=document.getElementById("wpn-arrow-down"),t=document.getElementById("wpn-others-cross-items-discounts");t.classList.contains("wpn-hidden")?(t.classList.remove("wpn-hidden"),t.style.display="block",e.setAttribute("transform","rotate(180)")):(t.classList.add("wpn-hidden"),t.style.display="none",e.setAttribute("transform","rotate(0)"))}));let a=document.createElement("div");a.id="wpn-others-cross-items-discounts",a.style.display="none",a.classList.add("wpn-hidden");for(let o in e)if(e.hasOwnProperty(o)){let r=e[o],s=r.promise,i=r.discount,c=document.createElement("div");if(c.style.position="relative",0===n)c.id="label-product-"+o,c.innerHTML=s,c.className="text text-primary line-item-discount-product",t.appendChild(c);else{let e=`${i}`,t=s.indexOf("OFF")+3,n=`
${e} ${-1!==t?s.slice(t):""}
`;c.id="label-product-"+o,c.innerHTML=n,c.className="cross-item-discount-promise-product",a.appendChild(c)}n++}Object.keys(e).length>1&&(t.appendChild(o),t.appendChild(a))}}(t)}}function E(e){function t(e){const t=255,n=255,o=255,r=function(e){if(e.startsWith("#")){let t,n,o;return 7===e.length?(t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16)):4===e.length&&(t=parseInt(e[1]+e[1],16),n=parseInt(e[2]+e[2],16),o=parseInt(e[3]+e[3],16)),{r:t,g:n,b:o}}if(e.startsWith("rgb")){const t=e.match(/\d+/g).map(Number);return{r:t[0],g:t[1],b:t[2]}}return{r:255,g:255,b:255}}(e);return Math.sqrt(Math.pow(r.r-t,2)+Math.pow(r.g-n,2)+Math.pow(r.b-o,2))}const n=getComputedStyle(document.documentElement).getPropertyValue(e).trim();if(n)return n;const o=document.querySelector('[data-store="head"]');if(!o)return null;const r=getComputedStyle(o).backgroundColor,a=getComputedStyle(o).color,s=t(r),i=t(a);return 0===s&&0===i?null:s>i?r:a}async function x(){const e=await d();if(e&&e.templates){const t=e.templates.line_item_label;let n=e.lineItems;if(w()){let e=A(LS.product.id,n);e.length>0&&(!function(e,t){let n=document.querySelector('[data-store="product-price-'+LS.product.id+'"]');null!==n&&e.forEach((function(e){let t=!1;if(e.excludedProducts&&(t=e.excludedProducts.includes(String(LS.product.id))),!t){let t=e.discount,o=document.getElementById("label-product-"+e.promiseId);null==o&&(o=document.createElement("div"),o.className="text text-primary line-item-discount-product",o.style.position="relative",o.id="label-product-"+e.promiseId),o.innerHTML=e.promise,n.appendChild(o),"progressive"===e.subtype&&t.length>1&&n.appendChild(function(e){let t=document.createElement("table");t.className="table table-striped",t.style.marginTop="20px";let n=document.createElement("tr"),o=document.createElement("th");o.innerHTML=h("Quantity");let r=document.createElement("th");return r.innerHTML=h("Discount"),n.appendChild(o),n.appendChild(r),t.appendChild(n),function(e,t){e.forEach((function(e){let n=document.createElement("tr"),o=document.createElement("td");o.innerHTML=e.minQuantityToApplyDiscount,n.appendChild(o);let r=document.createElement("td");r.innerHTML=e.percentageToDiscount+"% OFF",n.appendChild(r),t.appendChild(n)}))}(e,t),t}(t)),"object"==typeof e.promiseDetail&&e.subtype!==r&&n.appendChild(function(e){const t={all:j,product:k,category:B},n=document.createElement("div");n.style.marginTop="10px",n.style.marginBottom="10px";const o=document.createElement("div");o.classList.add("text");const r="wpn-promise-detail-"+e.promiseId,a=function(e){const t=document.createElement("div");return t.style.marginTop="10px",t.style.marginBottom="5px",t.classList.add("btn-link"),t.classList.add("wpn-promise-detail-toggler"),t.dataset.target=e,t.dataset.status="hidden",t.addEventListener("click",y),t}(r);let s=e.promiseDetail.filter;if(s in t){(0,t[s])(o,a,e.promiseDetail,parseInt(e.isCombinable))}if(n.appendChild(o),void 0!==e.promiseDetail.names&&e.promiseDetail.names.length>1){n.appendChild(a);const t=document.createElement("div");t.id=r,t.style.display="none";let o=e.promiseDetail.names.join(", ");e.promiseDetail.tooLong&&(o=o+" "+h("and others")),t.innerText=o,n.appendChild(t)}return n}(e))}}));const o=document.querySelector('[data-store="product-image-'+LS.product.id+'"]');null!==o&&O(o,e,t)}(e,t),f(n))}if(!window.location.href.includes("checkout")){I(e),function(){const e=document.getElementsByClassName("wpn-product-data"),t=document.getElementsByClassName("wpn-variants"),n=document.getElementsByClassName("wpn-product-variant");for(const e of n)e.addEventListener("click",Y);const o=document.getElementById("wpn-icon-close-gift-modal");o&&o.addEventListener("click",(function(){U(),G()}));for(const t of e)t.addEventListener("click",V);for(const e of t)e.addEventListener("click",V),(0===parseInt(e.dataset.hasMultipleVariants)||isNaN(parseInt(e.dataset.hasMultipleVariants)))&&e.closest(".wpn-product-card").addEventListener("click",(function(t){Y(t,e.dataset.singleProductId)}));const r=document.getElementById("wpn-button-add-gift"),a=document.getElementById("wpn-button-access-gift");null!==a&&a.addEventListener("click",(function(){Q()}));null!==r&&r.addEventListener("click",ne);const s=document.querySelectorAll(".wpn-choose-gift-label, .wpn-change-gift-label"),i=document.getElementById("wpn-gift-overlay");i&&i.addEventListener("click",(function(){U(),G()}));for(const e of s)e.addEventListener("click",Z)}(),function(){let e=E("--label-background");e=e||"#000",document.documentElement.style.setProperty("--label-background",e)}(),H=document.getElementsByClassName("wpn-product-card").length,ie(e.templates.progress_promotion_html,n),await J(LS.cart.subtotal/100),ee(L()),window._currentCartItems=LS.cart.items||[],document.addEventListener("cart.updated",(function(e){J(g(e),!0),ee(L())})),document.addEventListener("cart.viewed",(function(t){ie(e.templates.progress_promotion_html,n,!1)})),document.addEventListener("cart.item.added",(function(t){ie(e.templates.progress_promotion_html,n)})),document.addEventListener("cart.item.removed",(function(t){let o=t.detail.item_id;ie(e.templates.progress_promotion_html,n,o)})),f(n)}!function(e,t){document.querySelectorAll("[data-product-id]").forEach(n=>{let o=A(n.dataset.productId,e);o.length>0&&O(n,o,t)})}(n,t)}}const _={es:{"Applies to this products and can be combined with product from other selected categories.":"Aplica a este producto y es combinable con productos de otras categorías seleccionadas.","Applies to this products and can be combined with product from the same category ({{name}}).":"Aplica a este producto y es combinable con productos de la misma categoría ({{name}}).","Buy {{amount}} more to get a {{discount}}":"Compra {{amount}} más para obtener un {{discount}}","Can be combined with any other product from the store.":"Puede ser combinable con cualquier producto de la tienda.","Can be combined with other selected products.":"Promoción combinable con otros productos seleccionados.",Discount:"Descuento","Get a {{discount}} by buying more":"Consigue un {{discount}} comprando más","Hide categories":"Ocultar categorías","Hide products":"Ocultar productos",Quantity:"Cantidad","Show categories":"Mostrar categorías","More discounts":"Más descuentos","Limited time offer!":"¡Oferta por tiempo limitado!","Add {{remaining}} and get {{discount}}!":"Agrega {{remaining}} y obten {{discount}}!","Show products":"Mostrar productos","You already have a {{discount}} for buying in quantity":"Ya tienes un {{discount}} por comprar en cantidad","You already have a {{discount}} for exceeding {{amount}}":"Ya tienes un {{discount}} por superar {{amount}}","You already have a {{discount}}!":"¡Ya tenes un {{discount}}!","You have discounts on your purchase":"Tienes descuentos en tu compra","and more":"y más","Over {{amount}} and get {{discount}} on your purchase":"Supera los {{amount}} y obtén {{discount}} en tu compra","You have reached {{discount}} on your purchase":"Has alcanzado el {{discount}} en tu compra",or:"o"},pt:{"Applies to this products and can be combined with product from other selected categories.":"Aplica-se a este produto e pode ser combinado com produtos de outras categorias selecionadas.","Applies to this products and can be combined with product from the same category ({{name}}).":"Aplica-se a estes produtos e pode ser combinado com produtos da mesma categoria ({{name}}).","Buy {{amount}} more to get a {{discount}}":"Compre mais R{{amount}} para obter um {{discount}}","Can be combined with any other product from the store.":"Pode ser combinado com qualquer produto da loja.","Can be combined with other selected products.":"Promoção combinável com outros produtos selecionados.",Discount:"Desconto","Limited time offer!":"Oferta por tempo limitado!","Get a {{discount}} by buying more":"Conquiste um {{discount}} comprando mais","Hide categories":"Ocultar categorias","Hide products":"Ocultar produtos",Quantity:"Quantidade","More discounts":"Mais descontos","Show categories":"Mostrar categorias","Show products":"Mostrar produtos","You already have a {{discount}} for buying in quantity":"Você já tem um {{discount}} por comprar em quantidade","You already have a {{discount}} for exceeding {{amount}}":"Você já tem um {{discount}} por ultrapassar {{amount}}","You already have a {{discount}}!":"Você já tem um {{discount}}!","Add {{remaining}} and get {{discount}}!":"Você já tem um {{discount}}!","You have discounts on your purchase":"Você tem descontos em sua compra","and more":"e mais","Over {{amount}} and get {{discount}} on your purchase":"Acima de {{amount}} ganhe {{discount}} em sua compra","You have reached {{discount}} on your purchase":"Você alcançou {{discount}} de desconto na sua compra",or:"ou"}};function T(e,t,n){let o,r=!1;t>=2?(o=h("You already have a {{discount}} for buying in quantity"),r=!0):o=h("Get a {{discount}} by buying more");const a=e.discount[0].percentageToDiscount;return o=o.replace("{{discount}}",a+"% OFF"),{promiseText:o,allRulesCompleted:r,promiseId:e.promiseI}}function P(e,t,n){let o,r=!1,a=0;for(let s of e.discount){const e=parseInt(s.minQuantityToApplyDiscount||0);let i=s.percentageToDiscount+"% OFF";if(t>=e||t>=n?(o=h("You already have a {{discount}} for buying in quantity"),r=!0):(a=n-t,r=!1,o=h("Get a {{discount}} by buying more")),o=o.replace("{{discount}}",i),!r)break}return{promiseText:o,allRulesCompleted:r,promiseId:e.promiseId,remaining:a,total:n,currentQuantity:t}}function q(e,t,n){let o,r=!1,a=0;for(let s of e.discount){const e=s.minQuantityToApplyDiscount||0;let i=`${e}x${s.quantityToDiscount}`;if(t>=e||t>=n?(r=!0,o=h("You already have a {{discount}}!")):(a=n-t,r=!1,o=h("Add {{remaining}} and get {{discount}}!")),o=o.replace("{{remaining}}",a),o=o.replace("{{discount}}",i),!r)break}return{promiseText:o,allRulesCompleted:r,promiseId:e.promiseId,remaining:a,total:n}}async function M(){if(2526918!==o){const e=await d();if(e&&e.userItems){let t=e.userItems;if(t.length>0){w()&&function(e){const t='[data-store="product-price-'+LS.product.id+'"]';let n=document.querySelector(t);if(null!==n){let t=document.createElement("div");t.className="text text-primary user-item-discount",t.style.position="relative",t.innerHTML=e.promise,n.appendChild(t)}N(document.body,e,t,c.getProductNodeComparePriceSelector(),c.getProductNodeCurrentPriceSelector())}(t[0]),document.querySelectorAll("[data-product-id]").forEach(e=>{N(e,t[0],c.getProductPageProductPriceContainerSelector(),c.getProductPageComparePriceSelector(),c.getProductPageCurrentPriceSelector())})}}}}function A(e,t){return null!==e&&t&&Array.isArray(t)?t.filter(t=>{let n=t.products;return n["*"]||n[e]}):{}}function O(e,t,n){let o=e.querySelector(c.getProductLabelSelector());if(null!==o){if(null===o.querySelector(".wpn-label-discount")){let r=t[0];if(0===r.promise.length&&t.length>1&&(r=t[1]),r.promise.length>0){if(r.excludedProducts&&r.excludedProducts.includes(function(e){return e.dataset.productId?e.dataset.productId:e.dataset.store.split("-")[2]}(e)))return;let t=document.createElement("div"),a="utm"===r.subtype?h("Limited time offer!"):r.promise;t.innerHTML=n.replace(/{{promise}}/i,a),function(e){e.querySelectorAll('[data-store="product-item-promotion-label"]').forEach(e=>{e.remove()}),e.querySelectorAll('[data-store="product-item-offer-label"]').forEach(e=>{e.remove()})}(e),o.appendChild(t)}}}}function j(e,...t){e.innerText=h("Can be combined with any other product from the store.")}function k(e,t,n,o){o&&(e.innerText=h("Can be combined with other selected products.")),t.dataset.showText=h("Show products"),t.dataset.hideText=h("Hide products"),t.innerText=h("Show products")}function B(e,t,n,o){o&&(e.innerText=h("Applies to this products and can be combined with product from other selected categories."));let r=1===n.names.length,a=n.names[0];if(r){let t=h("Applies to this products and can be combined with product from the same category ({{name}}).");e.innerText=t.replace("{{name}}",a)}t.dataset.showText=h("Show categories"),t.dataset.hideText=h("Hide categories"),t.innerText=h("Show categories")}function N(e,t,n,o,r){const a=parseFloat(t.discount[0].discount)/100;let s=e.querySelector(n);if(null!==s){let t=s.querySelector(o),n=s.querySelector(r);if(null!==t&&null!==n){let o=S(t,n),r=S(n,t);if(!("originalPrice"in e.dataset)&&(e.dataset.originalPrice=o,o=parseFloat(o),r=parseFloat(r),r>0)){const e=r*(1-a);r===o&&b(t,o),b(n,e)}}}}let $=function(e=!1){const t=sessionStorage.getItem("_wpn_variant_selected"),n=new Map;if(t){const o=JSON.parse(t);e?Object.entries(o).forEach(([e,t])=>{n.set(e,t)}):Object.entries(o.values).forEach(([e,t])=>{n.set(e,t)})}return n}();const D=async function(){let e=sessionStorage.getItem("_wpn_promotion_with_variants");if(null!==e&&"undefined"!==e)return JSON.parse(e);const t=await d();if(t&&t.lineItems&&(e=t.lineItems.filter(e=>e.discount.some(e=>void 0!==e.variants)),e))return sessionStorage.setItem("_wpn_promotion_with_variants",JSON.stringify(e[0])),e[0];return sessionStorage.setItem("_wpn_promotion_with_variants",JSON.stringify([])),[]}();let H=0;function F(e,t){return(n=e.discount,new Promise(e=>{!function t(){n&&"function"==typeof n[Symbol.iterator]?e(n):setTimeout(t,500)}()})).then(e=>{const t=e.reduce((e,t)=>(e[t.minQuantityToApplyDiscount]=t,e),{});let n=new Map($),o=t[n.get("productRule")],r=void 0!==n.get("productId")?n.get("productId"):n.get("single-variant-product"),a=n.has("single-variant-product");n.delete("productId"),n.delete("productRule");let s=o.variants[r];if(a)return{variantId:s.variants[0].id,productId:r,minPromotionThreshold:parseInt(o.minQuantityToApplyDiscount)};let i=!1,c=null;for(const e of Object.values(s.variants)){if(0===e.values.length)continue;let t=Object.keys(e.values),o=Object.values(e.values);const r=Array.from(n.keys()),a=Array.from(n.values()),s=t.length===r.length&&t.every(e=>n.has(e));if(i=o.length===a.length&&o.every(e=>Array.from(n.values()).includes(e))&&s,i){c=e.id;break}}return i?{variantId:c,productId:r,minPromotionThreshold:parseInt(o.minQuantityToApplyDiscount)}:null});var n}function R(e,t){e.closest(".wpn-container-data-variants").querySelector(".wpn-variant-value").textContent=e.innerText;const n=document.getElementsByClassName("wpn-product-variant"),o=parseInt(e.dataset.productRule);D.then(e=>{var r,a;const s=function(e){const t={};for(const n in e){const o=e[n];for(const e in o.variants){const n=o.variants[e],r=Array.from($.values()),a=Object.values(n.values),s=Object.keys(n.values);let i=!1;for(let e of r)if(a.includes(e)){i=!0;break}if(i)for(let e=0;eparseInt(e.minQuantityToApplyDiscount)>=a).map(e=>e.variants))[0]),i=Object.keys(s);for(let e=0;e{e.style.display="block"}),document.querySelector(".wpn-product-list-container").classList.add("hidden"),document.querySelector(".gift-choose").classList.add("hidden"),document.querySelector(".gift-access").classList.remove("hidden"),document.querySelector("#wpn-button-add-gift").classList.add("hidden"),document.querySelector("#wpn-button-access-gift").classList.remove("hidden")):(document.querySelectorAll(".wpn-access-gift").forEach(e=>{e.style.display="none"}),document.querySelector(".wpn-product-list-container").classList.remove("hidden"),document.querySelector(".gift-choose").classList.remove("hidden"),document.querySelector(".gift-access").classList.add("hidden"),document.querySelector("#wpn-button-add-gift").classList.remove("hidden"),document.querySelector("#wpn-button-access-gift").classList.add("hidden"))}function G(){(function(){let e=!0;return document.querySelectorAll(".wpn-access-gift").forEach(t=>{"block"!==window.getComputedStyle(t).display&&(e=!1)}),e})()&&sessionStorage.setItem("wpn_showed_confetti_modal","1")}async function J(e,t=!1){const n=document.getElementsByClassName("wpn-product-container");if(0===n.length)return;const o=document.getElementById("wpn-button-add-container");let r=n[0],a=parseInt(r.dataset.amountToBeat),s=0;if(0!==$.size){let e=$.get("price");s=void 0!==e?e:0}e-=s;let i=a-parseInt(e);if(e<=a){const e=document.querySelectorAll(".wpn-remaining-amount.gift");for(let t=0;t0?o.classList.add("disabled"):o.classList.remove("disabled")}else o.classList.remove("disabled");const c=document.getElementsByClassName("wpn-choose-gift-label");for(let e=0;e{e.classList.remove("text-secondary"),e.classList.add("wpn-text-primary")}),Q(!0)):(r.classList.add("show-remaining-amount"),n.forEach(e=>{e.classList.remove("wpn-text-primary"),e.classList.add("text-secondary")}),Q())}}(i),z($)&&i<=0){sessionStorage.getItem("wpn_showed_confetti_modal")?sessionStorage.setItem("wpn_showed_confetti_modal","1"):(!function(){const e=document.getElementById("confetti-container");for(let t=0;t<200;t++){const t=document.createElement("div");t.classList.add("confetti"),t.style.backgroundColor=`hsl(${360*Math.random()}, 100%, 50%)`,t.style.left=100*Math.random()+"%",t.style.top="0%",e.appendChild(t)}}(),U(),setTimeout(W,500))}for(let t=0;t=parseInt(o.dataset.amountToBeat)?o.classList.remove("disabled"):o.classList.add("disabled");let r=o.querySelector(".wpn-product-card");r.classList.contains("active")&&r.classList.remove("active");let a=r.querySelector(".wpn-variants");a.classList.contains("inactive")||a.classList.add("inactive")}if(0!==$.size&&Q(!1),t&&!z($)){e{const t=500+1e3*Math.random(),n=-Math.PI/1.5+Math.random()*(2*Math.PI/3),o=20+100*Math.random();e.style.opacity=1,e.style.transition=`all ${t}ms ease-out`,e.style.transform=`translate(${Math.cos(n)*o}px, ${Math.sin(n)*o-100}px)`,setTimeout((function(){e.remove()}),t+50)})}function Z(e){e.target.closest(".wpn-choose-gift-label-container")&&(setTimeout(W,500),U())}function K(e){const t=document.querySelectorAll(".js-cart-item");let n=null;const o=Array.from(t).find((function(t){let n=t.querySelector('[data-component="line-item.name"]');if(n||(n=t.querySelector(".cart-item-name")),null==n)return console.error('El item del carro no tiene un elemento hijo con data-component="line-item.name" o .cart-item-name'),null;"A"!==n.tagName&&(n=n.querySelector("a"));let o=n.getAttribute("href");if(o=o.split("="),2!==o.length)return!1;return parseInt(o[1])===parseInt(e)}));return o&&(n=o.dataset.itemId),n}async function X(e,t,o=!0,r=!0){const a=K(t);if(null==a)return console.log("variant not found in the cart to be removed"),!1;let s=document.querySelector(`.js-cart-quantity-input[data-item-id="${parseInt(a)}"]`),i=0;if(s&&(i=s.value-1),r){await function(){const e=LS.cart.id;return new Promise((function(t,o){if(0!==$.size){fetch(`${n}/tiendanube/delete-variant-gift?cartId=${e}`,{method:"POST",mode:"cors"}).then(e=>e.json()).then(e=>{sessionStorage.removeItem("_wpn_variant_selected"),sessionStorage.removeItem("wpn_last_variant_added"),t(e.success)}).catch(e=>{console.error("error at remove cart item wpn: ",e),o(e)})}}))}()||console.error("error removing wpn item")}let c=[],d=encodeURIComponent(`quantity[${a}]`),l=encodeURIComponent(i);c.push(d+"="+l),c=c.join("&");fetch("/cart/update/",{method:"POST",body:c,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}}).then(e=>{o?window.location.reload():ee(!1)}).catch(e=>{console.error("error updating the cart: ",e)})}function ee(e=!0){const t=document.querySelectorAll(".wpn-choose-gift-label"),n=document.querySelectorAll(".wpn-change-gift-label"),o=document.getElementById("wpn-button-add-gift");null!==o&&n.forEach(n=>{e&&1!==H?(n.classList.remove("hidden"),o.textContent=o.dataset.changeGiftText,t.forEach(e=>{e.classList.add("hidden")})):(n.classList.add("hidden"),o.textContent=o.dataset.chooseGiftText,t.forEach(e=>{e.classList.remove("hidden")}))})}async function te(e){let t=sessionStorage.getItem("wpn_last_variant_added");null!==t&&await X(LS.cart.id,t,!1,!1),document.body.style.cursor="wait";let o=`${e.productId}_${e.variantId}`,r=LS.cart.id;return null!==r&&await async function(e,t){return new Promise((function(o,r){fetch(`${n}/tiendanube/add-variant-gift?variantsId[]=${[e]}&cartId=${t}`,{method:"POST",mode:"cors"}).then(e=>e.json()).then(e=>{U(),o(e.success)}).catch(e=>{console.error("error at add item to cart wpn: ",e),r(e)})}))}(o,r),e}async function ne(){F(await D).then(async e=>{$.get("productId")&&$.delete("productId"),$.get("productRule")&&$.delete("productRule");let t=$.get("single-variant-product")?[]:Array.from($.values());if(e){document.body.style.cursor="wait",await te(e)&&(await function(e,t=[]){let n="";if(t)for(let e=0;e`;let o=``;LS.addToCartEnhanced(jQueryNuvem(o))}(e.productId,t),setTimeout(()=>{let t=function(e){let t=document.querySelector(`.wpn-product-data[data-product-id="${e}"]`);if(t){let e=t.querySelector(".price");if(e){let t=e.textContent.trim();return parseInt(t.match(/[\d.]+/g).join(""))}console.error('Elemento con clase "price" no encontrado.')}else console.error("Producto con el productId especificado no encontrado.");return null}(e.productId);const n={variantId:e.variantId,values:Object.fromEntries($),productId:e.productId,minPromotionThreshold:e.minPromotionThreshold,price:t};sessionStorage.setItem("_wpn_variant_selected",JSON.stringify(n)),sessionStorage.setItem("wpn_last_variant_added",e.variantId),document.body.style.cursor="default",window.location.reload()},900))}else console.error("Error at process and add to cart")})}async function oe(e,t){let{isApplied:n,promotionMessage:o}=await function(e){return d().then((function(t){let n=0,o="",r=t.crossItems,a=!1;return Object.entries(r).forEach(([t,r])=>{let s=parseFloat(t);e<=s&&(s{t.forEach(t=>{if([r,a,s,i].includes(t.subtype))return;let d=parseInt(e.dataset.componentValue),l=e.dataset.itemId,u=!1;if(t.excludedProducts&&0!==t.excludedProducts.length&&(u=t.excludedProducts.includes(String(d))),(t.products[d]||t.products["*"])&&!u){c.has(t.promiseId)?c.get(t.promiseId).push(d):c.set(t.promiseId,[d]);let e="",s=0,i=parseInt(t.discount[t.discount.length-1].minQuantityToApplyDiscount),u=c.get(t.promiseId),p=function(e){if(ae.has(e))return ae.get(e);let t=document.querySelector('.js-cart-item[data-component-value="'+e+'"]');return t?ae.has(e)||ae.set(e,t):ae.has(e)&&ae.delete(e),ae.get(e)}(d),m=function(e,t,n,o,s=null){let i=0;if(o){let e=parseInt(o.dataset.itemId);if(e!==parseInt(s)){let t=LS.cart.items.filter(t=>t.item_id===e);const n=t.length>0?t[t.length-1]:null;let o=document.querySelector(`#product_form[data-store="product-form-${e}"] #quantity`);o||(o=document.querySelector(`.cart-quantity-input[data-item-id="${e}"]`));let r=o?parseInt(o.value,10):0;i+=n?n.quantity:r}}let c={progressive:(e,n)=>P(e,n,t),nxm:(e,n)=>q(e,n,t),[a]:(e,t)=>T(e,t)},d=[];for(const n of e.discount)if(n.subtype!==r&&"utm"!==n.subtype){let n=c[e.subtype];n&&d.push(n(e,i,t)),d=d.filter((e,t,n)=>t===n.findIndex(t=>t.promiseId===e.promiseId))}return d}(t,i,0,p,n);u.forEach(n=>{if(p){const r=m.filter(e=>e.allRulesCompleted),a=m.filter(e=>!e.allRulesCompleted);if(a.length>0)e=a[0].promiseText,s=a[0].remaining;else if(r.length>0){let t=r[r.length-1];e=t.promiseText,s=t.remaining}o[t.promiseId]||(o[t.promiseId]=[]);o[t.promiseId].some(e=>e.id===n)||o[t.promiseId].push({id:n,lineItemId:l,text:e,remaining:s,total:i,cartItem:p})}})}})}),o}function ie(e,t,n=null){let o=document.querySelectorAll(".js-cart-item");if(!o)return;let r=se(o,t,n),a={};Object.keys(r).forEach(t=>{let n,o,s;n=a[t]?a[t].oldProgressBarContainer:document.querySelector(".wpn-promo-"+t),n?(o=n.querySelector(".wpn-progress-container").style.backgroundColor,s=n.querySelector(".wpn-progress-bar").style.backgroundColor):[o,s]=de(),t in a||(a[t]={backgroundColor:o,progressColor:s,oldProgressBarContainer:n});for(const n of r[t]){let o="wpn-progress-bar-container-"+n.id,r=document.getElementById(o);if(document.getElementById(o)){r.getElementsByClassName("wpn-progress-text")[0].innerHTML=n.text}else r=re(n.cartItem,e,o,n.id,t);pe("line_items",{progressBarContainer:r,finalText:n.text,remaining:n.remaining,total:n.total,backgroundColor:a[t].backgroundColor,progressColor:a[t].progressColor})}})}function ce(e,t){return Math.floor(Math.random()*(t-e))+e}function de(e=!1){let t="#B5B5B5",n="#4F4F4F";if(!e){const e=ce(0,360),o=ce(40,80);t=`hsl(${e}, ${o}%, ${ce(60,80)}%)`,n=`hsl(${e}, ${o}%, ${ce(30,50)}%)`}return[t,n]}function le(e,t,n,o){let r=e.querySelector(".wpn-progress-bar");""===e.querySelector(".wpn-progress-container").style.backgroundColor&&""===r.style.backgroundColor&&(e.querySelector(".wpn-progress-container").style.backgroundColor=n,r.style.backgroundColor=o),r.style.width=t+"%"}function ue(e){let t=document.querySelector(".wpn-progress-cross-items");t.style.display=0===e.amount?"none":"inherit";let[n,o]=de(!0);const r=Object.keys(e.crossItemDiscounts),a=r[r.length-1];let s=parseInt(a);le(t,e.amount>s?100:e.amount/Math.floor(1.2*s)*100,n,o),t.querySelector(".wpn-progress-text").innerText=function(e,t){let n=null,o=null;for(let r in t){if(e<=parseFloat(r)){n=r;break}o=t[r]}let r=h("Over {{amount}} and get {{discount}} on your purchase"),a=Object.keys(t)[0];return n||o?n?(r=r.replace("{{amount}}",l(parseFloat(n))),r=r.replace("{{discount}}",t[n].discount),r):(r=h("You have reached {{discount}} on your purchase"),r=r.replace("{{discount}}",o.discount),r):(r=r.replace("{{amount}}",l(parseFloat(a))),r=r.replace("{{discount}}",t[a].discount),r)}(e.amount,e.crossItemDiscounts)}function pe(e,t){let n={cross_items:ue,line_items:me};e in n&&(0,n[e])(t)}function me(e){if(!document.getElementsByClassName("js-cart-item").length)return;let t=0===e.remaining?100:100*(e.total-e.remaining)/Math.floor(1.2*e.total);le(e.progressBarContainer,t,e.backgroundColor,e.progressColor),e.progressBarContainer.querySelector(".wpn-progress-text").innerText=e.finalText}let fe=document.querySelector(c.getCartSubtotalSelector());function ge(){x(),M(),C()}null!==fe&&async function(e){const t=await d();if(t&&t.templates){let n=document.createElement("div");n.innerHTML=t.templates.cross_items_container;let o=e.parentNode;if(o.insertBefore(n,e),0!==Object.keys(t.crossItems).length){!function(e,t,n){let o=document.getElementById("wpn-progress-cross-items-container");if(!n||!t||o)return;let r=document.createElement("div");r.innerHTML=e,r.id="wpn-progress-cross-items-container",r.classList.add("wpn-progress-template","wpn-progress-cross-items"),t.insertBefore(r,n)}(t.templates.progress_promotion_html,o,e),pe("cross_items",{amount:LS.cart.subtotal/100,crossItemDiscounts:t.crossItems})}document.addEventListener("cart.updated",(function(e){if(oe(g(e),n),0!==Object.keys(t.crossItems).length){pe("cross_items",{amount:g(e),crossItemDiscounts:t.crossItems})}})),void 0!==LS.cart&&await oe(LS.cart.subtotal/100,n)}}(fe),ge();const he=document.querySelector(c.getProductTableSelector());if(null!==he){const e={childList:!0,subtree:!1};new MutationObserver(ge).observe(he,e)}}});
//# sourceMappingURL=tn_text.js.map