!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(Depicter,(()=>(()=>{"use strict";var t={};(t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})})(t);const{Layer:e,env:i}=window.Depicter;return window.Depicter.externalLayers.wooAddToCart=class extends e{constructor(t,e,s,a,n,d){super(t,e,s,a,n,d),this.type="wooAddToCart",this.frame.classList.add(`${i.prefix}-button-layer`),this.frame.classList.add(`${i.prefix}-woo-add-to-cart-layer`),this.frame.classList.add(`${i.prefix}-no-swipe`)}_setupContent(){this.anchorElement=this.element.closest("a"),this.useAjax="true"===this.element.dataset.useAjax,this.isPurchasable="true"===this.element.dataset.purchasable,this.canUseAjax="true"===this.element.dataset.canUseAjax,this.productId=this.element.dataset.productId,this.addedLabel=this.element.dataset.addedLabel,this.cartPage=this.element.dataset.cartPage,this.isPurchasable||(this.element.classList.add(`${i.prefix}-button-disabled`),this.element.disabled=!0),this.loading=document.createElement("div"),this.loading.classList.add(`${i.prefix}-dot-flashing`),[...Array(3)].forEach((()=>{const t=document.createElement("span");this.loading.appendChild(t)})),this.buttonContent=this.element.querySelector(".dp-inner-content, .dp-button-content"),this.label=document.createElement("span");const t=Array.from(this.buttonContent.childNodes).find((t=>t.nodeType===Node.TEXT_NODE));t&&(this.label.classList.add(`${i.prefix}-button-label`),this.label.textContent=t.nodeValue,this.buttonContent.replaceChild(this.label,t)),this.element.appendChild(this.loading),this.anchorElement.addEventListener("click",this.onClickHandler.bind(this))}_toggleLoading(t){t?(this.buttonContent.style.visibility="hidden",this.loading.style.visibility="visible",this.loading.style.opacity=1,this.isLoading=!0):(this.buttonContent.style.visibility="visible",this.loading.style.visibility="hidden",this.loading.style.opacity=0,this.isLoading=!1)}onClickHandler(t){if(this.isLoading)return t.preventDefault(),void t.stopPropagation();if(this.useAjax&&this.canUseAjax&&!this.isProductAdded){t.preventDefault(),t.stopPropagation(),this._toggleLoading(!0);const e=new FormData;e.append("action","depicter-wc-add-to-cart"),e.append("success_message","Item has been added to your cart."),e.append("product_id",this.productId),e.append("quantity","1"),fetch(window.depicterConfig.ajaxApiUrl,{method:"POST",body:e}).then((t=>t.json())).then((t=>{const e=new CustomEvent("added_to_cart",{detail:{fragments:t.fragments,cart_hash:t.cart_hash,button:""}});document.body.dispatchEvent(e),this.isProductAdded=!0,this.label.innerHTML=this.addedLabel,this.anchorElement.href=this.cartPage,this._toggleLoading(!1)})).catch((t=>{console.error("Error:",t)}))}}},t})()));