
jQuery(document).ready(function ($) {

	let itemToDelete = null;
	let id = 0;

	$(document).on('click', '.pixelio-cart-abandon-recovery-more-remove-button', function (e) {
		e.preventDefault();
		id = $(this).data('template-id');
		itemToDelete = $(this).closest('tr');
		$('#pixelio-cart-abandon-recovery-more-remove-popup').fadeIn(200);
	});

	$(document).on('click', '.pixelio-cart-abandon-recovery-more-popup-cancel', function () {
		$('#pixelio-cart-abandon-recovery-more-remove-popup').fadeOut(200);
		itemToDelete = null;
		id = 0;
	});

	$(document).on('click', '.pixelio-cart-abandon-recovery-more-popup-confirm', function () {
		if (itemToDelete) {
			itemToDelete.remove();
			$('#pixelio-cart-abandon-recovery-more-remove-popup').fadeOut(200);
			itemToDelete = null;
			if (typeof window.pixelioAction2Callback === "function") {
				window.pixelioAction2Callback(id);
			}
			id = 0;
		}
	});

	$(document).on('click', '#pixelio-cart-abandon-recovery-more-remove-popup', function (e) {
		if ($(e.target).is('#pixelio-cart-abandon-recovery-more-remove-popup')) {
			$('#pixelio-cart-abandon-recovery-more-remove-popup').fadeOut(200);
			itemToDelete = null;
			id = 0;
		}
	});
});
