/**
 * AJAX utilities for Cart Recovery
 *
 * @package EDD\Pro\CartRecovery\Admin
 */

/**
 * Performs an AJAX POST request.
 *
 * @param {string} ajaxurl - The AJAX URL endpoint.
 * @param {Object} data     - The data to send in the request.
 * @return {Promise} Promise that resolves with JSON response.
 */
export async function ajaxPost( ajaxurl, data ) {
	const response = await fetch( ajaxurl, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded',
		},
		body: new URLSearchParams( data ),
	} );

	if ( ! response.ok ) {
		throw new Error( 'Network response was not ok' );
	}

	return response.json();
}
