(function() {
	var toggleLink = document.getElementById('sitefort-2fa-toggle-recovery');
	if (!toggleLink) {
		return;
	}

	var primarySection = document.getElementById(toggleLink.getAttribute('data-primary-section') || '');
	var primaryInput = document.getElementById(toggleLink.getAttribute('data-primary-input') || '');
	var recoverySection = document.getElementById('sitefort-2fa-recovery-section');
	var recoveryInput = document.getElementById('recovery_code');
	var toggleBackLabel = toggleLink.getAttribute('data-toggle-back-label') || '';
	var toggleRecoveryLabel = toggleLink.getAttribute('data-toggle-recovery-label') || '';

	if (!primarySection || !primaryInput || !recoverySection || !recoveryInput) {
		return;
	}

	toggleLink.addEventListener('click', function(event) {
		event.preventDefault();

		if (recoverySection.style.display === 'none') {
			recoverySection.style.display = '';
			primarySection.style.display = 'none';
			toggleLink.textContent = toggleBackLabel;
			primaryInput.value = '';
			recoveryInput.focus();
			return;
		}

		recoverySection.style.display = 'none';
		primarySection.style.display = '';
		toggleLink.textContent = toggleRecoveryLabel;
		recoveryInput.value = '';
		primaryInput.focus();
	});
}());
