// upload-image-to-wp.js
function uploadImageToWordPressMedia( imageBlob, filename, nonce, callback ) {
	var formData = new FormData();
	formData.append( 'action', 'alpha_upload_image' ); // Use the correct AJAX action for ALPHA_upload_image_handler
	formData.append( 'async-upload', imageBlob, filename );
	formData.append( 'name', filename );
	formData.append( 'nonce', nonce ); // The handler expects 'nonce' not '_wpnonce'

	fetch( window.ajaxurl, {
		method: 'POST',
		credentials: 'same-origin',
		body: formData,
	} )
		.then( function ( response ) {
			return response.json();
		} )
		.then( function ( data ) {
			if ( typeof callback === 'function' ) callback( data );
		} )
		.catch( function ( error ) {
			if ( typeof callback === 'function' )
				callback( { success: false, error: error } );
		} );
}
