/* Setup-prompt admin notice: persist dismissal per-user via admin-ajax.
   The notice HTML is rendered server-side (admin_notices hook); WP core
   ships the actual dismiss button + animation for `is-dismissible`. All
   we do here is wire the click → fetch so the choice survives reloads.

   Config comes from PrintPriceNotice global (wp_localize_script). */
( function () {
	function bind() {
		var notice = document.querySelector( '[data-printprice-notice="setup"]' );
		if ( ! notice ) {
			return;
		}
		var dismissBtn = notice.querySelector( '.notice-dismiss' );
		if ( ! dismissBtn ) {
			return;
		}
		dismissBtn.addEventListener( 'click', function () {
			var cfg = window.PrintPriceNotice || {};
			if ( ! cfg.ajaxUrl || ! cfg.nonce ) {
				return;
			}
			var body = new URLSearchParams();
			body.append( 'action', 'print_price_dismiss_setup_notice' );
			body.append( '_wpnonce', cfg.nonce );
			fetch( cfg.ajaxUrl, {
				method: 'POST',
				credentials: 'same-origin',
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				body: body.toString(),
			} ).catch( function () { /* ignore — worst case it nags once more next pageload */ } );
		} );
	}

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