/**
 * Shared RSM Suite admin UI helpers.
 */
( function () {
	'use strict';

	function initDismissibleNotes() {
		var notes = document.querySelectorAll( '[data-rsm-dismiss-key]' );
		if ( ! notes.length ) {
			return;
		}

		notes.forEach( function ( note ) {
			var key = note.getAttribute( 'data-rsm-dismiss-key' );
			var button = note.querySelector( '[data-rsm-dismiss]' );

			if ( ! key || ! button ) {
				return;
			}

			try {
				if ( window.localStorage && '1' === window.localStorage.getItem( key ) ) {
					note.hidden = true;
				}
			} catch ( e ) {}

			button.addEventListener( 'click', function () {
				note.hidden = true;
				try {
					if ( window.localStorage ) {
						window.localStorage.setItem( key, '1' );
					}
				} catch ( e ) {}
			} );
		} );
	}

	if ( document.readyState === 'loading' ) {
		document.addEventListener( 'DOMContentLoaded', initDismissibleNotes );
	} else {
		initDismissibleNotes();
	}
}() );
