/**
 * @file assets/js/adminjs/review-nudge.js
 * Dismissal handler for WordPress.org review request notices (.mbs-review-nudge).
 * Fires AJAX on both the "Maybe later" button and the WP core X-button.
 * @package MyBookShowroom
 * @since   1.1.0
 */

/* global ajaxurl, jQuery */

document.addEventListener( 'DOMContentLoaded', function () {
	'use strict';

	document.querySelectorAll( '.mbs-review-nudge' ).forEach( function ( notice ) {
		var nonce     = notice.dataset.nonce;
		var milestone = notice.dataset.milestone;

		function dismiss() {
			jQuery.post( ajaxurl, {
				action    : 'mbs_dismiss_review_nudge',
				nonce     : nonce,
				milestone : milestone,
			} );
			notice.remove();
		}

		var maybeBtn = notice.querySelector( '.mbs-nudge-dismiss-btn' );
		if ( maybeBtn ) {
			maybeBtn.addEventListener( 'click', dismiss );
		}

		var xBtn = notice.querySelector( '.notice-dismiss' );
		if ( xBtn ) {
			xBtn.addEventListener( 'click', dismiss );
		}
	} );
} );
