const obMiniCartState={policies:{"customer-mini-cart[age]":!1,"customer-mini-cart[privacy_policy]":!1},button:{"checkout-button-mini-cart":!0},cartRecommendation:{"aria-expanded":!0}},handleGTMChecked=(input,state)=>input.setAttribute("data-gtm-state",state),handleObMiniCartSubmit=event=>{const policies=obMiniCartState.policies,policiesChecked=Object.keys(obMiniCartState.policies).every(key=>policies[key]===!0);if(handleObMiniCartErrorMessage(policies),!policiesChecked)return event.preventDefault(),!1},handleObMiniCartErrorMessage=policies=>{const checkoutButton=document.getElementById("checkout-button-mini-cart");for(const[key,value]of Object.entries(policies))if(value==!1){let policieId=document.getElementById(`${key}`);policieId&&(policieId.style.borderColor="#DE1616"),document.getElementById("customer-mini-cart[privacy_policy]")?.parentNode.setAttribute("checkbox-tooltip","Por favor, rellene la box arriba"),checkoutButton&&(checkoutButton.style.background="#CCCCCC")}else checkoutButton&&(checkoutButton.style.background="#007E78")},handleObMiniCartCheckBox=event=>{const input=event.target,checkoutButton=document.getElementById("checkout-button-mini-cart");if(obMiniCartState.policies[input.id]=input.checked,input.checked){input.checked=!0;let policieId=document.getElementById(`${input.id}`);obMiniCartState.policies["customer-mini-cart[age]"]&&obMiniCartState.policies["customer-mini-cart[privacy_policy]"]&&(document.getElementById("customer-mini-cart[privacy_policy]")?.parentNode.removeAttribute("checkbox-tooltip"),checkoutButton&&(checkoutButton.style.background="#007E78")),policieId&&(policieId.style.borderColor="")}else input.checked=!1,checkoutButton&&(checkoutButton.style.background="#CCCCCC");handleGTMChecked(input,input.checked)},handleCartRecommendationsOnRerender=()=>{const fromStateAriaExpanded=obMiniCartState.cartRecommendation["aria-expanded"],cartRecommendation=document.querySelector("cart-drawer-recommendations");cartRecommendation&&cartRecommendation.setAttribute("aria-expanded",fromStateAriaExpanded)},handleCartRecommendations=thisElement=>{const buttonToggle=thisElement.querySelector(".mini-cart__recommendations-button");let domAriaExpanded=thisElement.getAttribute("aria-expanded")==="true";if(!buttonToggle)return;handleCartRecommendationsSlider(thisElement,!1,0),buttonToggle.addEventListener("click",()=>{thisElement.setAttribute("aria-expanded",!domAriaExpanded),domAriaExpanded=!domAriaExpanded,obMiniCartState.cartRecommendation["aria-expanded"]=domAriaExpanded})},handleCartRecommendationsSlider=(thisElement,ready,currentIndex)=>{if(ready)return;const wrapper=thisElement;if(!wrapper)return;const items=thisElement.querySelector(".mini-cart__recommendations-list");items.addEventListener("scroll",event=>{const totalWidth=wrapper.getBoundingClientRect().width,itemWidth=items.children[0].getBoundingClientRect().width,scrollX=event.target.scrollLeft+(totalWidth-itemWidth);currentIndex=parseInt(scrollX/itemWidth),updateDots()}),ready=!0;const dotsContainer=thisElement.querySelector(".cart-drawer-recommendations__dots"),children=items.children,updateScroll=()=>{const x=children[currentIndex].getBoundingClientRect().width*currentIndex;items.scrollTo(x,0)},updateDots=()=>{const dots=dotsContainer.children;Array.from(dots).forEach((dot,index)=>{currentIndex===index?dot.classList.add("selected"):dot.classList.contains("selected")&&dot.classList.remove("selected")})};Array.from(children).forEach((element,index)=>{const dot=document.createElement("div");dot.classList.add("cart-drawer-recommendations__nav-dot"),dot.onclick=()=>{currentIndex=index,updateScroll(),updateDots()},dotsContainer.appendChild(dot)});const buttonPrev=thisElement.querySelector(".cart-drawer-recommendations__button-prev");buttonPrev.onclick=()=>{currentIndex<=0?currentIndex=children.length-1:currentIndex--,updateScroll(),updateDots()};const buttonNext=thisElement.querySelector(".cart-drawer-recommendations__button-next");buttonNext.onclick=()=>{currentIndex>=children.length-1?currentIndex=0:currentIndex++,updateScroll(),updateDots()},updateDots()};document.addEventListener("cart-drawer-recommendations:loaded",event=>{const{thisElement}=event.detail;thisElement&&handleCartRecommendations(thisElement)}),document.addEventListener("mini-cart:toggle",()=>{Object.keys(obMiniCartState.policies).forEach(key=>{const input=document.getElementById(key),checkoutButton=document.getElementById("checkout-button-mini-cart");if(input)input.checked||(checkoutButton.style.background="#CCCCCC");else return;obMiniCartState.policies[input.id]=input.checked,input.removeEventListener("click",handleObMiniCartCheckBox),input.addEventListener("click",handleObMiniCartCheckBox)}),Object.keys(obMiniCartState.button).forEach(key=>{const button=document.getElementById(key);button&&(button.removeEventListener("click",handleObMiniCartSubmit),button.addEventListener("click",handleObMiniCartSubmit))})}),document.addEventListener("mini-cart:rerender",()=>{Object.keys(obMiniCartState.policies).forEach(key=>{const input=document.getElementById(key);input&&(input.checked=obMiniCartState.policies[key],input.removeEventListener("click",handleObMiniCartCheckBox),input.addEventListener("click",handleObMiniCartCheckBox))}),Object.keys(obMiniCartState.button).forEach(key=>{const button=document.getElementById(key);button&&(button.removeEventListener("click",handleObMiniCartSubmit),button.addEventListener("click",handleObMiniCartSubmit))});const policies=obMiniCartState.policies;handleCartRecommendationsOnRerender(),handleObMiniCartErrorMessage(policies)}),document.addEventListener("cart:updated",function(event){setTimeout(function(){InCartUpsell.prototype.findOfferWhenReady()},1e3)}); //# sourceMappingURL=/cdn/shop/t/115/assets/ob-mini-cart.js.map?v=147846275796767403201709747188