;(()=>{"use strict";var e;(e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})({}),(e=jQuery)(document).ready(function(){e(".eaw-saved-cart-actions button").on("click",function(t){t.preventDefault();const r=e(this).data("savecartid");e(this).hasClass("eaw-delete-button")?Swal.fire({title:"Are you sure?",text:"You won't be able to revert this!",icon:"warning",showCancelButton:!0,confirmButtonColor:"#3085d6",cancelButtonColor:"#d33",confirmButtonText:"Yes, delete it!"}).then(t=>{t.isConfirmed&&wp.ajax.post("ccpeawDeleteSavedCart",{saveCartId:r,eaw_nonce:ccpeaw.nonce}).done(function(t){t.success?(Swal.fire("Deleted!","Your cart has been deleted.","success"),e(`[data-savecartid="${r}"]`).closest(".eaw-saved-cart-item").hide("fast")):Swal.fire("Error!",t.data.message||"An error occurred while deleting the cart.","error")}).fail(function(){Swal.fire("Error!","There was a problem with the request. Please try again later.","error")})}):e(this).hasClass("eaw-restore-button")&&Swal.fire({title:"Are you sure?",text:"You won't be able to revert this!",icon:"warning",showCancelButton:!0,confirmButtonColor:"#3085d6",cancelButtonColor:"#d33",confirmButtonText:"Yes, restore it!"}).then(e=>{e.isConfirmed&&wp.ajax.post("ccpeawRestoreSavedCart",{saveCartId:r,eaw_nonce:ccpeaw.nonce}).done(function(e){e.success?Swal.fire("Restored!","Your cart has been restored.","success"):Swal.fire("Error!",e.data.message||"An error occurred while restoring the cart.","error")}).fail(function(){Swal.fire("Error!","There was a problem with the request. Please try again later.","error")})})}),e("#eaw-save-button").on("click",function(e){e.preventDefault(),Swal.fire({title:"Add save cart name",input:"text",showCancelButton:!0,confirmButtonText:"Save",showLoaderOnConfirm:!0,preConfirm:e=>e?wp.ajax.post("ccpeawSaveCart",{eaw_nonce:ccpeaw.nonce,cart_name:e}):(Swal.showValidationMessage("Cart name is required"),!1)}).then(e=>{e.isConfirmed&&Swal.fire({title:"Saved!",text:"Your cart has been saved.",icon:"success",confirmButtonText:"Go to Saved Cart",showCancelButton:!0,cancelButtonText:"Close",cancelButtonColor:"#d40000"}).then(e=>{e.isConfirmed&&(window.location.href="/my-account/saved-cart/")})})}),e("#eaw-copy-button").on("click",function(t){t.preventDefault();const r=e(this).data("savecartid"),a=e(this).data("current-page")||"cart";console.log("saveCartId:",r,"currentPage:",a),Swal.fire({title:"Generating Copy Link...",didOpen:()=>Swal.showLoading()}),wp.ajax.post("ccpeawCopyCart",{cartId:r,currentPage:a,eaw_nonce:ccpeaw.nonce}).done(function(e){if(e.success){const t=e.data;Swal.fire({title:"Share Link Generated!",html:`<input type="text" value="${t}" id="shareUrlInput" readonly style="width:100%;padding:5px;">`,icon:"success",showCancelButton:!0,confirmButtonText:"Copy Link"}).then(e=>{e.isConfirmed&&(document.getElementById("shareUrlInput").select(),document.execCommand("copy"),Swal.fire("Copied!","The link has been copied to your clipboard.","success"))})}else Swal.fire("Error!",e.data.message||"An error occurred.","error")}).fail(function(){Swal.fire("Error!","An error occurred while generating the link.","error")})}),e("#eaw-share-buttons i").not("#eaw-copy-button").on("click",function(t){t.preventDefault();const r=e(this).data("network"),a=e(this).data("current-page")||"cart";Swal.fire({title:"Generating Share Link...",didOpen:()=>Swal.showLoading()}),wp.ajax.post("ccpeawShareCartOnSocial",{network:r,currentPage:a,eaw_nonce:ccpeaw.nonce}).done(function(e){e.success?(window.open(e.data.url,"_blank"),Swal.close()):Swal.fire("Error!",e.data.message||"An error occurred.","error")}).fail(function(){Swal.fire("Error!","An error occurred while generating the link.","error")}).always(function(){Swal.hideLoading()})})})})();