;(()=>{"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-wishlist-handler").on("click",function(t){t.preventDefault();const i=e(this),o=i.data("productid");Swal.fire({title:"Processing...",text:"Please wait while we process your request.",allowOutsideClick:!1,didOpen:()=>{Swal.showLoading()}}),wp.ajax.post("ccpeawHandleWishlist",{productId:o,eaw_nonce:ccpeaw.nonce}).done(function(t){Swal.close(),t.success?(Swal.fire({icon:"success",title:"Wishlist",text:t.message,showCancelButton:!0,confirmButtonText:"View Wishlist",cancelButtonText:"Close"}).then(e=>{e.isConfirmed&&(window.location.href="/my-account/wishlist/")}),e("#eaw-wishlist-items").html(t.html),i.find("span").addClass("eaw-icon-wishlist-2")):Swal.fire({icon:"error",title:"Error",text:t.message})}).fail(function(e){Swal.close(),Swal.fire({icon:"warning",title:"Attention!",text:e?.message||"Something went wrong.",showCancelButton:!0,confirmButtonText:"View Wishlist",cancelButtonText:"Close"}).then(e=>{e.isConfirmed?window.location.href="/my-account/wishlist/":Swal.fire({icon:"question",title:"Remove from Wishlist?",text:"Do you want to remove this product from your wishlist?",showCancelButton:!0,confirmButtonText:"Yes, Remove",cancelButtonText:"No"}).then(e=>{e.isConfirmed&&(wp.ajax.post("ccpeawDeleteFromWishList",{productId:o,eaw_nonce:ccpeaw.nonce}),console.log("Item removed from wishlist.",i),i.find("span").removeClass().addClass("eaw-icon-wishlist-1"))})})})}),e(".eaw-wishlist-get-handler").on("click",function(t){t.preventDefault();const i=e(this).data("userid"),o=e(this).data("productid");Swal.fire({title:"Loading Wishlist...",text:"Please wait while we fetch your wishlist.",allowOutsideClick:!1,didOpen:()=>{Swal.showLoading()}}),wp.ajax.post("ccpeawGetWishlist",{userId:i,productId:o,eaw_nonce:ccpeaw.nonce}).done(function(e){Swal.close(),e.success?Swal.fire({title:"Wishlist",html:e.html,showCancelButton:!0,cancelButtonText:"Close",showConfirmButton:!1}):Swal.fire({icon:"error",title:"Error",text:e.message})}).fail(function(e){Swal.close(),Swal.fire({icon:"error",title:"Error",text:`Error: ${e.message}`})})}),jQuery(function(e){e(".eaw-buttons-actions .eaw-action-button").on("click",function(t){if("variable"===e(this).data("producttype"))return;t.preventDefault();const i=e(this),o=i.data("productid"),s=ccpeaw.nonce,n=i.closest(".eaw-wishlist-item").find(".eaw-wishlist-quantity-input").val()||1;if(!o||!s)return void console.warn("Missing product ID or nonce.");let a="",l="",c="";if(i.hasClass("eaw-add-to-cart-button"))a="ccpeawAddToCartById",l="add_to_cart",c="Adding to cart...";else{if(!i.hasClass("eaw-delete-button"))return void console.warn("Unknown action for button:",i.attr("class"));a="ccpeawDeleteFromWishList",l="delete",c="Removing from wishlist..."}i.prop("disabled",!0).attr("aria-busy","true"),Swal.fire({title:c,text:"Please wait while we process your request.",allowOutsideClick:!1,didOpen:()=>{Swal.showLoading()}}),wp.ajax.post(a,{productId:o,quantity:n,eaw_nonce:s}).done(function(t){Swal.close(),t.success?"add_to_cart"===l?Swal.fire({icon:"success",title:"Success",text:t.message,showCancelButton:!0,confirmButtonText:"View Cart",cancelButtonText:"Close"}).then(e=>{e.isConfirmed&&(window.location.href="/cart/")}):"delete"===l&&Swal.fire({icon:"success",title:"Product removed from wishlist",text:t.message}).then(t=>{t.isConfirmed&&e('.eaw-wishlist-items .eaw-wishlist-item[data-productid="'+o+'"]').hide("fast")}):Swal.fire({icon:"error",title:"Error",text:t.message||"An error occurred."})}).fail(function(e){Swal.close(),Swal.fire({icon:"error",title:`${e.status}`,text:`Error: ${e.message}`})}).always(function(){i.prop("disabled",!1).attr("aria-busy","false")})})})})})();