/**
 * Security page interactions — CAPTCHA toggle, Brute Force toggle, Concurrent Logins toggle.
 *
 * @package PrivexPasswordProtect
 */
document.addEventListener('DOMContentLoaded', function() {
	// CAPTCHA provider select → show/hide key fields.
	var captchaSelect = document.getElementById('ppmstr-captcha-provider');
	var captchaKeys = document.querySelector('.ppmstr-captcha-keys');
	if (captchaSelect && captchaKeys) {
		captchaSelect.addEventListener('change', function() {
			if (this.value === 'none') {
				captchaKeys.style.display = 'none';
			} else {
				captchaKeys.style.display = 'block';
			}
		});
	}

	// Brute force toggle.
	var limitLoginToggle = document.querySelector('input[name="ppmstr_limit_login_enabled"]');
	var limitLoginSettings = document.getElementById('ppmstr-limit-login-settings');
	if (limitLoginToggle && limitLoginSettings) {
		limitLoginToggle.addEventListener('change', function() {
			limitLoginSettings.style.opacity = this.checked ? '1' : '0.5';
			limitLoginSettings.style.pointerEvents = this.checked ? 'auto' : 'none';
		});
	}

	// Concurrent logins toggle.
	var concurrentLoginsToggle = document.querySelector('input[name="ppmstr_concurrent_logins_enabled"]');
	var concurrentLoginsSettings = document.getElementById('ppmstr-concurrent-logins-settings');
	if (concurrentLoginsToggle && concurrentLoginsSettings) {
		concurrentLoginsToggle.addEventListener('change', function() {
			concurrentLoginsSettings.style.opacity = this.checked ? '1' : '0.5';
			concurrentLoginsSettings.style.pointerEvents = this.checked ? 'auto' : 'none';
		});
	}
});
