/**
 * Settings page interactions — Remove password button handler.
 *
 * @package PrivexPasswordProtect
 */
document.addEventListener('DOMContentLoaded', function() {
	var removeBtns = document.querySelectorAll('.ppmstr-remove-pw-btn');
	removeBtns.forEach(function(btn) {
		btn.addEventListener('click', function() {
			var wrap = this.closest('.ppmstr-saved-indicator');
			if (wrap) {
				var cb = wrap.querySelector('.ppmstr-clear-pw-cb');
				if (cb) {
					cb.checked = true;
				}
				wrap.style.display = 'none';

				// Attempt to clear the corresponding password field visually.
				var container = wrap.parentElement;
				var input = container.querySelector('input[type="password"]');
				if (input) {
					input.value = '';
					input.focus();
				}
			}
		});
	});
});
