1class CartAPI{constructor(timeout=5e3){this._timeout=timeout}async _fetch(url,options={}){const controller=new AbortController,timerId=setTimeout(()=>controller.abort(),this._timeout);try{const res=await fetch(url,{...options,signal:controller.signal});if(!res.ok){const err=await res.json().catch(()=>({}));throw new Error(err.description||err.message||`HTTP ${res.status}`)}return res.json()}finally{clearTimeout(timerId)}}add(variantId,quantity=1,properties={}){return this._fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:variantId,quantity,properties})})}update(lineItemKey,quantity){return this._fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:lineItemKey,quantity})})}remove(lineItemKey){return this.update(lineItemKey,0)}updateCart(payload={}){return this._fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)})}get(){return this._fetch("/cart.js")}clear(){return this._fetch("/cart/clear.js",{method:"POST"})}}class CartNotifier{constructor(){this._listeners={}}on(event,cb){return this._listeners[event]||(this._listeners[event]=[]),this._listeners[event].push(cb),()=>this.off(event,cb)}off(event,cb){this._listeners[event]&&(this._listeners[event]=this._listeners[event].filter(fn=>fn!==cb))}emit(event,data){this._listeners[event]?.forEach(cb=>cb(data)),document.dispatchEvent(new CustomEvent(`cart:${event}`,{bubbles:!0,detail:data}))}}class CartManager{constructor(){this._api=new CartAPI,this._notifier=new CartNotifier}on(event,cb){return this._notifier.on(event,cb)}off(event,cb){this._notifier.off(event,cb)}_pushAddToCartEvent({variantId,quantity,data,button}){if(!["accepted","true"].includes(localStorage.getItem("theme-cookie-bar-accepted")))return;const card=button?.closest?.("[data-product-card]"),plp=card?.closest?.("[data-plp-page-type]"),itemPrice=data?.price!=null?Number(data.price)/100:Number(card?.dataset.analyticsItemPrice||0),item={item_id:String(data?.product_id??card?.dataset.analyticsItemId??""),item_name:data?.product_title??data?.title??card?.dataset.analyticsItemName,item_brand:card?.dataset.analyticsItemBrand||"Charth",item_variant:String(data?.variant_id??variantId??card?.dataset.analyticsItemVariantId??""),item_variant_name:data?.variant_title||void 0,price:itemPrice,quantity:Number(quantity)||1,item_list_name:plp?.dataset.plpListName||void 0,item_url:card?.dataset.analyticsItemUrl||data?.url||void 0};!item.item_id||!item.item_name||(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"add_to_cart",event_id:`add-to-cart-${Date.now()}-${variantId}`,page_type:document.body.className.match(/template-([\w-]+)/)?.[1]||void 0,ecommerce:{currency:"BRL",value:item.price*item.quantity,items:[item]}}))}async add(variantId,{quantity=1,properties={},button,action="open_drawer"}={}){button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.add(variantId,quantity,properties);return button&&window.ButtonFeedback?.success(button),this._notifier.emit("added",{variantId,quantity,data,action}),this._pushAddToCartEvent({variantId,quantity,data,button}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"add",error:error.message,variantId}),{success:!1,error:error.message}}}async remove(lineItemKey,{button}={}){button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.remove(lineItemKey);return button&&window.ButtonFeedback?.success(button),this._notifier.emit("removed",{lineItemKey,data}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"remove",error:error.message,lineItemKey}),{success:!1,error:error.message}}}async update(lineItemKey,quantity,{button}={}){button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.update(lineItemKey,quantity);return button&&window.ButtonFeedback?.success(button),this._notifier.emit("updated",{lineItemKey,quantity,data}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"update",error:error.message,lineItemKey}),{success:!1,error:error.message}}}async updateAttributes(attributes={},{button}={}){button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.updateCart({attributes});return button&&window.ButtonFeedback?.success(button),this._notifier.emit("updated",{attributes,data}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"updateAttributes",error:error.message,attributes}),{success:!1,error:error.message}}}async applyDiscount(code,{button}={}){const trimmedCode=`${code||""}`.trim();if(!trimmedCode)return{success:!1,error:"Missing discount code"};button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.updateCart({discount:trimmedCode});if(!((data.cart_level_discount_applications||[]).length>0))throw await this._api.updateCart({discount:""}),new Error("C\xF3digo Inv\xE1lido");return button&&window.ButtonFeedback?.success(button),this._notifier.emit("updated",{discount:trimmedCode,data}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"applyDiscount",error:error.message,discount:trimmedCode}),{success:!1,error:error.message}}}async removeDiscount({button}={}){button&&window.ButtonFeedback?.loading(button);try{const data=await this._api.updateCart({discount:""});return button&&window.ButtonFeedback?.success(button),this._notifier.emit("updated",{discount:"",data}),{success:!0,data}}catch(error){return button&&window.ButtonFeedback?.error(button),this._notifier.emit("error",{action:"removeDiscount",error:error.message}),{success:!1,error:error.message}}}async get(){try{return{success:!0,data:await this._api.get()}}catch(error){return{success:!1,error:error.message}}}async clear(){try{const data=await this._api.clear();return this._notifier.emit("cleared",{data}),{success:!0,data}}catch(error){return{success:!1,error:error.message}}}}window.CartManager=new CartManager,window.CartManager.on("added",refreshFreeShippingBar),window.CartManager.on("removed",refreshFreeShippingBar),window.CartManager.on("updated",refreshFreeShippingBar),window.CartManager.on("cleared",refreshFreeShippingBar);async function refreshFreeShippingBar(){const cart=await(await fetch("/cart.js")).json(),free_shipping_container=document.querySelector(".free-shipping-bar"),percentage_bar=document.querySelector(".free-shipping-bar__progress"),free_shipping_default=Number(free_shipping_container.getAttribute("data-free-shipping")),subtotal=cart.items_subtotal_price/100,result=free_shipping_default-subtotal,percentage=subtotal/free_shipping_default*100;console.log(percentage);const message=document.querySelector(".free-shipping-bar__message");result>0?(message.innerHTML=`Faltam <b> R$ ${result} </b> para voc\xEA garantir FRETE GR\xC1TIS`,percentage_bar.style.width=`${percentage}%`):(message.innerHTML="<b>Voc\xEA ganhou FRETE GR\xC1TIS</b>",percentage_bar.style.width="100%")} 2//# sourceMappingURL=/cdn/shop/t/58/assets/manager-cart.js.map?v=107269935333273579191790025504
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.