/**
 * Persist the dismissal of the theme's admin notices.
 *
 * @package Euphony_Blocks
 */

( function ( $ ) {
	'use strict';

	$( function () {
		$( document ).on( 'click', '.notice[data-dismissible] .notice-dismiss', function () {
			if ( typeof euphonyBlocksPAnD === 'undefined' ) {
				return;
			}

			var attr = $( this ).closest( '.notice[data-dismissible]' ).attr( 'data-dismissible' ) || '';

			if ( ! attr ) {
				return;
			}

			// "notice-seven-7" -> option name "notice-seven", length "7".
			var parts  = attr.split( '-' );
			var length = parts.pop();
			var option = parts.join( '-' );

			if ( ! option ) {
				return;
			}

			$.post( euphonyBlocksPAnD.ajaxUrl, {
				action: euphonyBlocksPAnD.action,
				option_name: option,
				dismissible_length: length,
				nonce: euphonyBlocksPAnD.nonce
			} );
		} );
	} );
}( jQuery ) );
