(()=>{"use strict";const e=e=>{const t=`; ${document.cookie}`.split(`; ${e}=`);if(2===t.length)return t.pop().split(";").shift()},t=(e,t)=>{if(e){const t=document.querySelector(e);if(t)return t}if(t)for(let e=0;e{t.parentNode.insertBefore(e,t.nextSibling)},n=e=>{const t=Object.keys(e),o={};for(let n=0;n"legacy"===e?i[t]?.[r]?.paymentButtonSelector??i[t]?.paymentButtonSelector:"io"===e?"div.vtex-add-to-cart-button-0-x-buttonDataContainer":void 0,c={macId:()=>e("VtexRCMacIdv7"),sessionId:()=>e("VtexRCSessionIdv7")};function d(e,t){return async()=>{const o=l(),n=await o("/api/checkout/pub/orderForm?refreshOutdatedData=true","POST",null,"json"),r=n.success?n.payload:{};return{orderFormId:r.orderFormId,allySlug:e,merchantDomain:location.origin,selectedItem:t,orderDetails:r}}}function l(){return async(e,t,o,n)=>{const r=(i=e,(a=c)?(Object.keys(a).forEach((function(e){i=i.replace(new RegExp(`{{${e}}}`,"g"),a[e]())})),i):i);var i,a;const d={json:"application/json",text:"application/text",form:"application/x-www-form-urlencoded"},l={};return d[n]&&(l["Content-Type"]=d[n]),await fetch(`${location.origin}${r}`,{method:t,headers:l,...o?{body:(e=>"json"===n?JSON.stringify(e):e)(o)}:{}}).then((async e=>{if(!e.ok)return{success:!1,status:e.status,statusText:await e.text()};const t=e?.headers?.get("Content-Type")??"";return{success:!0,...{...t.includes("json")?{payload:await e.json()}:{},...t.includes("text")?{payload:await e.text()}:{}}}})).catch((e=>e))}}async function s(e,t,o,n,r){return await fetch(`${e}/api/checkout/pub/orderForm/${t}/items/update`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({noSplitItem:!0,orderItems:[{id:o,quantity:0,seller:n,index:r,hasBundleItems:!1}]})}).then((e=>e.json())).catch((e=>null))}!function(){const e=window?.__RUNTIME__?.accountId?"io":"legacy",c=(window.dataLayer&&(window?.dataLayer[0]?.pageCategory||(window?.dataLayer?.find((e=>e.pageCategory))||{}).pageCategory))??(()=>{const e=window.location.pathname;return"/"===e?"Home":e.endsWith("/p")||e.includes("/p?")?"Product":""})(),u=document.querySelector('script[data-id][data-name="vtexAddiWidget"]'),m={allySlug:u.getAttribute("data-ally-slug"),IOevents:{productClick:"vtex:productClick",productView:"vtex:productView"}},g={showBanner:!1,bannerId:"",htmlElementRef:null},f={productPrice:null,customCSS:{},htmlElementRef:null,genericSelectorsRef:[".product__price",".precioProducto",".precio",".plugin-preco",".productPrice",".price-box",".priceProduct",".seletor-sku"]},h={htmlElementRef:null,genericSelectorsRef:[a(e,m.allySlug)]},p=()=>{w()},b=()=>{const e=window.skuJson||{},t=e.skus&&e.skus.find((e=>e.available)),o=window.decimalDigits||0;f.productPrice=t.bestPrice/10**o,S(),A()},y=e=>{const{selectedSku:t,sku:o}=e?.product||{},n=t??o,r=n.sellers&&n.sellers.find((e=>e?.commertialOffer?.AvailableQuantity)),i=window.decimalDigits||0;f.productPrice=r.commertialOffer.Price/10**i,S(),A()},w=()=>{g.showBanner="true"===u.getAttribute("data-show-banner"),g.bannerId=u.getAttribute("data-banner-id"),g.htmlElementRef=u.getAttribute("data-banner-element-reference"),g.showBanner&&function(e,{bannerId:n,htmlElementRef:r}){const i=document.querySelector("addi-home-banner");i&&i.remove();const a=document.createElement("addi-home-banner");n&&(a.setAttribute("ally-slug",e),a.setAttribute("banner-id",n));const c=t(r,null);o(a,c)}(m.allySlug,g)},S=()=>{if(!f?.htmlElementRef){const e=u.getAttribute("data-element-reference"),o=t(e,f.genericSelectorsRef);if(!o)return void console.log(`[ADDI - Awareness Widget] No Element Node was found for the selector ${e}`);f.htmlElementRef=o}f?.customCSS||(f.customCSS=(e=>{const t={borderColor:e.getAttribute("widget-border-color"),borderRadius:e.getAttribute("widget-border-radius"),fontColor:e.getAttribute("widget-font-color"),fontFamily:e.getAttribute("widget-font-family"),fontSize:e.getAttribute("widget-font-size"),badgeBackgroundColor:e.getAttribute("widget-badge-background-color"),infoBackgroundColor:e.getAttribute("widget-info-background-color"),iconType:e.getAttribute("widget-addi-icon-type"),iconSize:e.getAttribute("widget-addi-icon-size"),margin:e.getAttribute("widget-margin")},o={backgroundColor:e.getAttribute("modal-background-color"),fontColor:e.getAttribute("modal-font-color"),fontFamily:e.getAttribute("modal-font-family"),priceColor:e.getAttribute("modal-price-color"),badgeBackgroundColor:e.getAttribute("modal-badge-background-color"),badgeFontColor:e.getAttribute("modal-badge-font-color"),badgeBorderRadius:e.getAttribute("modal-badge-border-radius"),cardColor:e.getAttribute("modal-card-color"),buttonBorderColor:e.getAttribute("modal-button-border-color"),buttonBorderRadius:e.getAttribute("modal-button-border-radius"),buttonBackgroundColor:e.getAttribute("modal-button-background-color"),buttonFontColor:e.getAttribute("modal-button-font-color")};return JSON.stringify({widget:n(t),modal:n(o)})})(u)),k(m.allySlug,f)},k=(e,{productPrice:t,customCSS:n,htmlElementRef:r})=>{const i=document.querySelector("addi-product-widget");t&&i&&i.remove();const a=i??document.createElement("addi-product-widget");a.setAttribute("ally-slug",e),a.setAttribute("price",t),a.setAttribute("country","co"),a.setAttribute("custom-widget-styles",JSON.stringify(n)),o(a,r)},A=()=>{if(!h?.htmlElementRef){const e=u.getAttribute("data-checkout-element-reference"),o=t(e,h.genericSelectorsRef);if(!o)return void console.log(`[ADDI - Expedited Widget] No Element Node was found for the selector ${e}`);h.htmlElementRef=o,"DIV"!==o.tagName&&(h.htmlElementRef=o.parentElement)}v(m.allySlug,h)},v=(e,{htmlElementRef:t})=>{const n=document.querySelector("addi-one-click-checkout");n&&n.remove();const a=document.createElement("addi-one-click-checkout");a.setAttribute("ally-slug",e),a.addEventListener("checkoutStarted",(t=>{!async function(e,t){const o=e?.detail?.selectedItem;if(!o)return console.log("[ADDI] There is no way no notify the selected item"),o("ErrorUnexpected",null);const n=location.origin,a=await async function(e,t){const o=(e=>{const t=i[e]?.[r]??i[e];return()=>{const e=document.querySelectorAll(t.paymentButtonSelector),o=document.querySelectorAll(t.paymentButtonSelectorBack);if(!e?.length)return{};let n="";for(const t of e){const e=t.getAttribute("href");e&&e.startsWith("/checkout/")&&(n=e)}for(const e of o){const t=e.getAttribute("href");t&&t.startsWith("/checkout/")&&(n=t)}if(!n)return{};const r=new URL(`${location.origin}${n}`);return{sku:r?.searchParams?.get("sku"),seller:r?.searchParams?.get("seller"),qty:t.qtyCounterSelector?document.querySelector(t.qtyCounterSelector)?.value:"1"}}})(e);if(!o)return;const n=await async function(e){return await fetch(`${e}/api/checkout/pub/orderForm?refreshOutdatedData=true`,{method:"POST",headers:{"Content-Type":"application/json"}}).then((e=>e.json()))}(t),{sku:a,qty:c,seller:d}=o();return[a,c,d,n].every((e=>!!e))?{sku:a,qty:c,seller:d,orderForm:n}:void 0}(t,n);if(!a)return console.log("[ADDI] Is not possible to read the selected SKU, quantity or seller. The checkout can't start"),o("ErrorNoSkuOrQuantity",null);const{sku:c,qty:u,seller:m,orderForm:g}=a,{orderFormId:f}=g;await async function(e,t){return await fetch(`${e}/api/checkout/pub/orderForm/${t}/messages/clear`,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"}).then((e=>e.json())).catch((e=>null))}(n,f);const h=g?.items?.findIndex((e=>e.id===c));if(h>=0){const e=await s(n,f,c,m,h);if(!e)return console.log("[ADDI] Something went wrong removing the current item from the cart"),o("ErrorRemovingItem",null);if(e.messages.length)return console.log("[ADDI] Something is not right after trying to remove the item. Please check the messages"),o("ErrorRemovingItem",null)}const p=await async function(e,t,o,n,r){return await fetch(`${e}/api/checkout/pub/orderForm/${t}/items`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderItems:[{id:o,quantity:n,seller:r}]})}).then((e=>e.json())).catch((e=>null))}(n,f,c,u,m);if(!p)return console.log("[ADDI] Something went wrong adding the item to the cart"),o("ErrorAddingItem",null);if(p.messages.some((e=>"withoutStock"===e.code))){const e=p?.items?.findIndex((e=>e.id===c));return await s(n,f,c,m,e),console.log("[ADDI] Selected item out of stock"),o("ErrorItemOutOfStock",null)}if(p.messages.length)return console.log("[ADDI] Something is not right after trying to add the item. Please check the messages"),o("ErrorAddingItem",null);o("Ok",{getCheckoutData:d(t,function(e){const t=window.skuJson.skus.find((t=>t.sku===+e));return t?{id:t.sku,description:t.skuname,value:t.fullSellingPrice,imageUrl:t.image}:null}(c)),apiCaller:l()})}(t,e)})),o(a,t)};!function(){const e=["addi","addibr"].includes(m.allySlug)?{pdpWidget:"https://cdn.addi-staging.com/product-details-widget/staging/v1/product-details-widget.esm.js",homeBanner:"https://cdn.addi-staging.com/home-banner-widget/staging/v1/home-banner-widget.esm.js"}:{pdpWidget:"https://cdn.addi.com/product-details-widget/prod/v1/product-details-widget.esm.js",homeBanner:"https://cdn.addi.com/home-banner-widget/prod/v1/home-banner-widget.esm.js"};if("Home"===c){const t=document.createElement("script");t.type="module",t.src=e.homeBanner,document.head.append(t)}if("Product"===c){const t=document.createElement("script");t.type="module",t.src=e.pdpWidget,document.head.append(t),S()}}(),(()=>{if("Product"===c){if("legacy"===e)return(()=>{try{const e=new Vtex.JSEvents.Listener("batchBuyListener",b);skuEventDispatcher&&skuEventDispatcher.addListener(skuDataReceivedEventName,e)}catch(e){console.log("[ADDI] Something when wrong trying to subscribe a Vtex Batch Listener ",e)}window.addEventListener("skuSelected.vtex",b),document.addEventListener("readystatechange",(e=>{"complete"===e.target.readyState&&b()}))})();if("io"===e)return void window.addEventListener("message",(e=>{const t=e.data;t.eventName===m.IOevents.productView&&y(t)}))}document.addEventListener("readystatechange",(e=>{"complete"===e.target.readyState&&p()}))})()}()})();