
try{
jQuery(document).ready(function(){MicroModal.init();function updateStepTitles(){if(jQuery('[data-step-title]').length){jQuery('.step-title-wrapper').remove();jQuery('.wp2fa-setup-content').prepend('<div class="step-title-wrapper"></div>');var counter=1;jQuery('[data-step-title]:not(.hidden)').each(function(){var stepLabel=jQuery(this).attr('data-step-title');if(jQuery(this).hasClass('active')){jQuery('.step-title-wrapper').append(`<span class="step-title active-step-title"><span>${counter}</span> ${stepLabel}</span>`);}else{jQuery('.step-title-wrapper').append(`<span class="step-title"><span>${counter}</span> ${stepLabel}</span>`);}
counter++;});}
checkWizardOffset();setTimeout(function(){jQuery('.step-setting-wrapper.active input[type="tel"] ').focus();},200);}
updateStepTitles();jQuery('body').on('click','.step-title',function(e){var currentLabel=jQuery(this).text().substr(2);jQuery('[data-step-title]:not(.hidden)').each(function(){var currentStep=jQuery(this);jQuery('[data-step-title]').removeClass('active');jQuery('.step-title').removeClass('active-step-title');var stepLabel=jQuery(this).attr('data-step-title');jQuery(`[data-step-title="${currentLabel}"]`).addClass('active');});updateStepTitles();});jQuery('[data-unhide-when-checked]').each(function(){if(jQuery(this).is(':checked')){const thingToShow=jQuery(this).attr('data-unhide-when-checked');jQuery(thingToShow).show(0);}});jQuery('body').on('click','[for="all-users"], [for="certain-roles-only"]',function(e){jQuery('.step-setting-wrapper.hidden').removeClass('hidden').addClass('un-hidden');updateStepTitles();});jQuery('body').on('click','[for="do-not-enforce"]',function(e){jQuery('.step-setting-wrapper.un-hidden').removeClass('un-hidden').addClass('hidden');updateStepTitles();});jQuery('body').on('click','.modal__btn',function(e){e.preventDefault();});jQuery('body').on('keypress','.wp2fa-modal',function(event){var keycode=(event.keyCode?event.keyCode:event.which);if('13'==keycode){return false;}});jQuery(document).on('click','[data-open-configure-2fa-wizard]',function(event){jQuery(window).off("beforeunload")
event.preventDefault();wp2fa_fireWizard();});jQuery(document).on('click','.step-setting-wrapper.active .option-pill input[type="checkbox"]',function(e){if('backup-codes'!==this.id&&!jQuery(this).hasClass('disabled')){if(true!==jQuery('#geek').prop('checked')&&true!==jQuery('#basic').prop('checked')){jQuery('#backup-codes').addClass('disabled');jQuery('label[for=\'backup-codes\']').addClass('disabled');window.backupCodes=jQuery('#backup-codes').prop('checked');jQuery('#backup-codes').prop('checked',false);if(jQuery('[name="next_step_setting"]').length){jQuery('[name="next_step_setting"]').addClass('disabled').attr('name','next_step_setting_disabled');}}else{jQuery('#backup-codes').removeClass('disabled');jQuery('label[for=\'backup-codes\']').removeClass('disabled');if('undefined'!==window.backupCodes){jQuery('#backup-codes').prop('checked',window.backupCodes);}
if(jQuery('[name="next_step_setting_disabled"]').length){jQuery('[name="next_step_setting_disabled"]').removeClass('disabled').attr('name','next_step_setting');}}}else{if(!jQuery(this).hasClass('disabled')){window.backupCodes=jQuery('#backup-codes').prop('checked');}else{jQuery('#backup-codes').prop('checked',false);}}});jQuery(document).on('click touchend','.radio-cells label, .radio-cells input[type="radio"]',function(e){jQuery('.option-pill').removeClass('isSelected');jQuery('.radio-cells input[type="radio"]:checked').closest('.option-pill').addClass('isSelected');});jQuery('.wizard-tooltip').each(function(){var contentDiv=jQuery(this).attr('data-tooltip-content');var ourItem=jQuery(this);if(jQuery('['+contentDiv+']').length){var content=jQuery('['+contentDiv+']').clone();jQuery(ourItem).append(content);}});jQuery(document).on('click touchend','.wizard-tooltip',function(e){var contentDiv=jQuery(this).attr('data-tooltip-content');var ourItem=jQuery(this);if(jQuery(this).hasClass('isOpen')){jQuery('.inline-helper').slideDown();}else{jQuery('[data-tooltip-content]').removeClass('isOpen');setTimeout(function(){if(jQuery('.inline-helper').length>2){jQuery('.inline-helper').not('['+contentDiv+']').slideUp();}},100);setTimeout(function(){if(jQuery('.inline-helper').length>2){jQuery('.inline-helper').not('['+contentDiv+']').remove();}},600);if(jQuery('['+contentDiv+']').length){var content=jQuery('['+contentDiv+']').html();jQuery('<div class="inline-helper" '+contentDiv+'>'+content+'</div>').insertAfter('.radio-cells');jQuery('.inline-helper').slideDown();}
jQuery(ourItem).addClass('isOpen');}});jQuery(document).on('click','.wp-2fa-method-select input[type="checkbox"]',function(e){let role_suffix=('global'===jQuery(this).data('role'))?'':'-'+jQuery(this).data('role');if('zero-email'+role_suffix===this.id&&true===jQuery(this).prop('checked')){jQuery(this).closest('fieldset#2fa-method-select'+role_suffix).find('div.method-wrapper').each(function(){if(jQuery(this).find('input[type="checkbox"]').length){if('zero-email'+role_suffix!==jQuery(this).find('input[type="checkbox"]').attr('id')){jQuery(this).find('input[type="checkbox"]').prop('checked',false);jQuery(this).find('label').addClass('disabled');}}});jQuery('label[for=backup-codes'+role_suffix+']').removeClass('disabled');if(jQuery('#enable-email-backup'+((''===role_suffix)?'-global':role_suffix)).length){jQuery('#enable-email-backup'+((''===role_suffix)?'-global':role_suffix)).prop('checked',false);jQuery('label[for=enable-email-backup'+((''===role_suffix)?'-global':role_suffix)).addClass('disabled');}}
if('zero-email'+role_suffix===this.id&&false===jQuery(this).prop('checked')){jQuery(this).closest('fieldset#2fa-method-select'+role_suffix).find('div.method-wrapper').each(function(){if(jQuery(this).find('input[type="checkbox"]').length){if('zero-email'+role_suffix!==jQuery(this).find('input[type="checkbox"]').attr('id')){jQuery(this).find('label').removeClass('disabled');}}});if(jQuery('#enable-email-backup'+((''===role_suffix)?'-global':role_suffix)).length){jQuery('label[for=enable-email-backup'+((''===role_suffix)?'-global':role_suffix)).removeClass('disabled');}}
if('backup-codes'+role_suffix!==this.id&&!jQuery(this).hasClass('disabled')){let backDisabled=false;if(true!==jQuery('#totp'+role_suffix).prop('checked')&&true!==jQuery('#hotp'+role_suffix).prop('checked')){backDisabled=true;if(jQuery('#oob'+role_suffix).length){if(true===jQuery('#oob'+role_suffix).prop('checked')){backDisabled=false;}}
if(jQuery('#authy'+role_suffix).length){setTimeout(function(){},2000);if(true===jQuery('#authy'+role_suffix).prop('checked')){backDisabled=false;}}
if(jQuery('#twilio'+role_suffix).length){setTimeout(function(){},2000);if(true===jQuery('#twilio'+role_suffix).prop('checked')){backDisabled=false;}}
if(jQuery('#yubico'+role_suffix).length){setTimeout(function(){},2000);if(true===jQuery('#yubico'+role_suffix).prop('checked')){backDisabled=false;}}
if(jQuery('#zero-email'+role_suffix).length){setTimeout(function(){},2000);if(true===jQuery('#zero-email'+role_suffix).prop('checked')){backDisabled=false;}}
if(jQuery('#passkeys'+role_suffix).length&&true===jQuery('#passkeys'+role_suffix).prop('checked')&&backDisabled===true){jQuery('#enable-email-backup'+role_suffix).addClass('disabled');jQuery('label[for="enable-email-backup'+role_suffix+'"]').addClass('disabled');jQuery('.email-backup-options'+role_suffix).addClass('disabled');}}
if(backDisabled){jQuery('#backup-codes'+role_suffix).addClass('disabled');jQuery('label[for="backup-codes'+role_suffix+'"]').addClass('disabled');window.backupCodes=jQuery('#backup-codes'+role_suffix).prop('checked');jQuery('#backup-codes'+role_suffix).prop('checked',false);jQuery('[for="all-users"], [for="certain-roles-only"]').addClass('disabled');}else{jQuery('[for="all-users"], [for="certain-roles-only"]').removeClass('disabled');jQuery('#backup-codes'+role_suffix).removeClass('disabled');jQuery('label[for="backup-codes'+role_suffix+'"]').removeClass('disabled');if('undefined'!==window.backupCodes){jQuery('#backup-codes'+role_suffix).prop('checked',window.backupCodes);}
jQuery('#enable-email-backup'+role_suffix).removeClass('disabled');jQuery('label[for="enable-email-backup'+role_suffix+'"]').removeClass('disabled');jQuery('.email-backup-options'+role_suffix).removeClass('disabled');}}else{if(!jQuery(this).hasClass('disabled')){window.backupCodes=jQuery('#backup-codes'+role_suffix).prop('checked');}else{jQuery('#backup-codes'+role_suffix).prop('checked',false);}}});jQuery(document).on('click','.wp2fa-setup-form .wp-2fa-method-select input[type="checkbox"]',function(e){let twilio=false;let authy=false;let zero_mail=false;if(jQuery('#twilio').length){if(jQuery('#twilio[data-sid-setup-wizard]').length&&jQuery('#wizard-sid-key').is(':visible')){twilio=false;}else{twilio=jQuery('#twilio').prop('checked');}}
if(jQuery('#authy').length){if(jQuery('#authy[data-api-setup-wizard]').length&&jQuery('#wizard-api-key').is(':visible')){authy=false;}else{authy=jQuery('#authy').prop('checked');}}
if(jQuery('#zero-email').length){zero_mail=jQuery('#zero-email').prop('checked');}
if(true!==jQuery('#totp').prop('checked')&&true!==jQuery('#hotp').prop('checked')&&true!==jQuery('#oob').prop('checked')&&true!==authy&&true!==twilio&&true!==zero_mail){let showAlert=true;if(jQuery(this).is(jQuery('input#authy.disabled'))&&jQuery('#wizard-api-key').is(':visible')){showAlert=false;}
if(jQuery(this).is(jQuery('input#twilio.disabled'))&&jQuery('#wizard-sid-key').is(':visible')){showAlert=false;}
if(showAlert){alert('Please select at least one 2FA method');}
jQuery('button.button[name="next_step_setting"]').prop('disabled',true);jQuery('button.button[name="next_step_setting"]').addClass('disabled');}else{jQuery('button.button[name="next_step_setting"]').prop('disabled',false);jQuery('button.button[name="next_step_setting"]').removeClass('disabled');}});jQuery(document).on('click','[data-close-2fa-modal]',function(e){e.preventDefault();jQuery(window).off("beforeunload");var modalToClose=`#${  jQuery( this ).closest( '.wp2fa-modal' ).attr( 'id' )}`;jQuery(modalToClose).removeClass('is-open').attr('aria-hidden','true');if('reLogin'in wp2faWizardData&&wp2faWizardData.reLoginEnabled==jQuery.trim(wp2faWizardData.reLogin)){jQuery.ajax({type:'POST',url:wp2faData.ajaxURL,data:{action:'custom_ajax_logout',_wpnonce:wp2faWizardData.nonce,},success:function(r){if('redirectToUrl'in wp2faWizardData&&''!=jQuery.trim(wp2faWizardData.redirectToUrl)){window.location.replace(wp2faWizardData.redirectToUrl);}else{removeShowParam();}}});}});jQuery(document).on('click','[data-close-2fa-modal-and-refresh]',function(e){e.preventDefault();jQuery(window).off("beforeunload");var modalToClose=`#${  jQuery( this ).closest( '.wp2fa-modal' ).attr( 'id' )}`;jQuery(modalToClose).removeClass('is-open').attr('aria-hidden','true');if(jQuery('#wp-2fa-manual-backup-codes-trigger').length){removeShowParam();}else{if('reLogin'in wp2faWizardData&&wp2faWizardData.reLoginEnabled==jQuery.trim(wp2faWizardData.reLogin)){jQuery.ajax({type:'POST',url:wp2faData.ajaxURL,data:{action:'custom_ajax_logout',_wpnonce:wp2faWizardData.nonce,},success:function(r){if('redirectToUrl'in wp2faWizardData&&''!=jQuery.trim(wp2faWizardData.redirectToUrl)){window.location.replace(wp2faWizardData.redirectToUrl);}else{removeShowParam();}}});}else{removeShowParam();}}});jQuery(document).on('click','[data-validate-authcode-ajax]',function(e){e.preventDefault();const thisButton=jQuery(this);let actionToRun='validate_authcode_via_ajax';let authcode=false;if(jQuery('#wp-2fa-totp-authcode').length&&jQuery('#wp-2fa-totp-authcode').val().length){authcode=true;}
if(typeof jQuery(this).data('oob-test')!=='undefined'){actionToRun='validate_oob_authcode_via_ajax';}
const nonceValue=jQuery(this).attr('data-nonce');var values={};jQuery.each(jQuery('.wp-2fa-user-profile-form :input, .wp2fa-modal :input').serializeArray(),function(i,field){values[field.name]=field.value;});const currentPageURL=window.location.href;const form=values;jQuery.ajax({type:'POST',dataType:'json',url:wp2faData.ajaxURL,data:{action:actionToRun,form:values,_wpnonce:nonceValue,},complete:function(data){if(false===data.responseJSON.success){jQuery(thisButton).parent().find('.verification-response').html(`<span style="color:red">${data.responseJSON.data['error']}</span>`);}
if(true===data.responseJSON.success){let nextSubStep=jQuery('#2fa-wizard-config-backup-codes');if(authcode){if(jQuery('#2fa-wizard-backup-methods').length){nextSubStep=jQuery('#2fa-wizard-backup-methods');}else if(jQuery('#2fa-wizard-email-backup-selected').length){nextSubStep=jQuery('#2fa-wizard-email-backup-selected');}}
jQuery(this).parent().parent().find('.active').not('.step-setting-wrapper').removeClass('active');jQuery('.wizard-step.active').removeClass('active');jQuery(nextSubStep).addClass('active');jQuery(document).on('click','#select-backup-method',function(e){e.preventDefault();var backupRadio=jQuery("input[name=backup_method_select]:checked");jQuery('.wizard-step.active').removeClass('active');jQuery('#'+backupRadio.data('step')).addClass('active');});jQuery(document).on('click','[name="save_step"], [data-close-2fa-modal]',function(){if('reLogin'in wp2faWizardData&&wp2faWizardData.reLoginEnabled==jQuery.trim(wp2faWizardData.reLogin)){jQuery.ajax({type:'POST',url:wp2faData.ajaxURL,data:{action:'custom_ajax_logout',_wpnonce:nonceValue,},success:function(r){if('redirectToUrl'in wp2faWizardData&&''!=jQuery.trim(wp2faWizardData.redirectToUrl)){window.location.replace(wp2faWizardData.redirectToUrl);}else{removeShowParam();}}});}else{if('redirectToUrl'in wp2faWizardData&&''!=jQuery.trim(wp2faWizardData.redirectToUrl)){window.location.replace(wp2faWizardData.redirectToUrl);}else{removeShowParam();}}});}}},);});jQuery('body').on('click','.contains-hidden-inputs input[type="radio"]',function(e){if(jQuery(this).hasClass('js-nested')){return;}
jQuery(this).closest('.contains-hidden-inputs').find('.hidden').hide(200);if(jQuery(this).is('[data-unhide-when-checked]')){const thingToShow=jQuery(this).attr('data-unhide-when-checked');if(jQuery(this).is(':checked')){jQuery(thingToShow).slideDown(200);}}});jQuery(document).on('click','.dismiss-user-configure-nag',function(){const thisNotice=jQuery(this).closest('.notice');jQuery.ajax({url:wp2faData.ajaxURL,data:{action:'dismiss_nag'},complete:function(){jQuery(thisNotice).slideUp();},});});jQuery(document).on('click','.dismiss-user-reconfigure-nag',function(){const thisNotice=jQuery(this).closest('.notice');jQuery.ajax({url:wp2faData.ajaxURL,data:{action:'wp2fa_dismiss_reconfigure_nag'},complete:function(data){jQuery(thisNotice).slideUp();},});});jQuery(document).on('click','[data-trigger-account-unlock]',function(){const nonce=jQuery(this).attr('data-nonce');const account=jQuery(this).attr('data-account-to-unlock');jQuery.ajax({url:wp2faData.ajaxURL,data:{action:'unlock_account',user_id:account,wp_2fa_nonce:nonce}});});jQuery(document).on('click','.remove-2fa',function(e){e.preventDefault();});jQuery('body').on('click','#2fa-wizard-totp .button[name="next_step_setting"]',function(e){e.preventDefault;const currentSubStep=jQuery(this).closest('.step-setting-wrapper.active');const nextSubStep=jQuery(currentSubStep).nextAll('div:not(.hidden)').filter(':first');jQuery(currentSubStep).removeClass('active');jQuery(nextSubStep).addClass('active');updateStepTitles();});jQuery('body').on('click','.wp2fa-first-time-wizard .button[name="next_step_setting"]',function(e){e.preventDefault;const currentSubStep=jQuery(this).closest('.step-setting-wrapper.active');const nextSubStep=jQuery(currentSubStep).nextAll('div:not(.hidden)').filter(':first');jQuery(currentSubStep).removeClass('active');jQuery(nextSubStep).addClass('active');updateStepTitles();});jQuery(document).on('click','.modal_logout',function(e){e.preventDefault();if(jQuery('#confirm-logout').length){MicroModal.show('confirm-logout');jQuery('.button-confirm-logout').blur();}});jQuery(document).on('click touchend','.button-confirm-logout',function(e){e.preventDefault();jQuery.ajax({type:'POST',url:wp2faData.ajaxURL,data:{action:'wp2fa_logout_account',_wpnonce:jQuery('.modal_logout').data('nonce'),},complete:function(data){location.reload();},});});jQuery(document).on('click','.modal_cancel',function(e){e.preventDefault();if(jQuery('#notify-users').length){MicroModal.show('notify-users');jQuery('.button-confirm').blur();}});jQuery(document).on('click touchend','.button-confirm',function(e){e.preventDefault();MicroModal.close('configure-2fa');MicroModal.close('notify-users');jQuery('.inline-helper').remove();if('reLogin'in wp2faWizardData&&wp2faWizardData.reLoginEnabled==jQuery.trim(wp2faWizardData.reLogin)){jQuery.ajax({type:'POST',url:wp2faData.ajaxURL,data:{action:'custom_ajax_logout',_wpnonce:wp2faWizardData.nonce,},success:function(r){if('redirectToUrl'in wp2faWizardData&&''!=jQuery.trim(wp2faWizardData.redirectToUrl)){window.location.replace(wp2faWizardData.redirectToUrl);}else{removeShowParam();}}});}else{removeShowParam();}});jQuery(document).on('click touchend','.button-decline',function(e){e.preventDefault();});jQuery(document).on('click','#close-settings',function(e){e.preventDefault();MicroModal.close('notify-admin-settings-page');window.location.replace(jQuery(this).data('redirect-url'));});jQuery(document).on('click','.first-time-wizard',function(e){e.preventDefault();MicroModal.show('notify-admin-settings-page');});jQuery(document).on('click','[data-trigger-remove-2fa]',function(){const nonce=jQuery(this).attr('data-nonce');const account=jQuery(this).attr('data-user-id');jQuery.ajax({url:wp2faData.ajaxURL,data:{action:'remove_user_2fa',user_id:account,wp_2fa_nonce:nonce},complete:function(data){location.reload();},});});jQuery(document).on('click','[data-trigger-remove-2fa-backup-email]',function(){const nonce=jQuery(this).attr('data-nonce');const account=jQuery(this).attr('data-user-id');jQuery.ajax({url:wp2faData.ajaxURL,data:{action:'remove_backup_email',user_id:account,wp_2fa_nonce:nonce},complete:function(data){location.reload();},});});jQuery(document).on('click','[data-submit-2fa-form]',function(e){jQuery('#submit').click();});function validateEmail(email){var re=/\S+@\S+\.\S+/;return re.test(email);}
jQuery(document).on('click','[data-trigger-setup-email]',function(e){let actionToRun='send_authentication_setup_email';var emailAddress=false;var inputUsed='';if(jQuery('#use_custom_email').prop('checked')){emailAddress=jQuery('#custom-email-address').val();inputUsed=jQuery('#custom-email-address');}else{emailAddress=jQuery('#use_wp_email').val();inputUsed=jQuery('#use_wp_email');}
if(typeof jQuery(this).data('oob-test')!=='undefined'){actionToRun='send_authentication_oob_setup_email';emailAddress=jQuery('#use_wp_oob_email').val();if(jQuery('#use_custom_oob_email').prop('checked')){emailAddress=jQuery('#custom-oob-email-address').val();inputUsed=jQuery('#custom-oob-email-address');}}
if(!validateEmail(emailAddress)||false==emailAddress){e.preventDefault();let errMsg=jQuery('#2fa-error-msg');if(errMsg.length){errMsg.remove();}
if(jQuery(this).hasClass('resend-email-code')){if(jQuery('#wp-2fa-email-authcode').is(":visible")){inputUsed=jQuery('#wp-2fa-email-authcode');}else if(jQuery('#wp-2fa-oob-authcode').is(":visible")){inputUsed=jQuery('#wp-2fa-oob-authcode');}}
jQuery('<span id="2fa-error-msg" style="color:red;">'+wp2faData.invalidEmail+'</span>').insertAfter(inputUsed);return false;}
if(jQuery(this).hasClass('resend-email-code')){var updateBtnText=true;var originalBtnText=jQuery(this).text();if(jQuery('#wp-2fa-email-authcode').is(":visible")){inputUsed=jQuery('#wp-2fa-email-authcode');}else if(jQuery('#wp-2fa-oob-authcode').is(":visible")){inputUsed=jQuery('#wp-2fa-oob-authcode');}}else{const currentSubStep=jQuery(this).closest('.step-setting-wrapper.active');const nextSubStep=currentSubStep.nextAll('div:not(.hidden)').filter(':first');jQuery(currentSubStep).removeClass('active');nextSubStep.addClass('active');updateStepTitles();}
const userID=jQuery(this).attr('data-user-id');const nonce=jQuery(this).attr('data-nonce');const thisBtn=jQuery(this);jQuery.ajax({type:'POST',dataType:'json',url:wp2faData.ajaxURL,data:{action:actionToRun,email_address:emailAddress,user_id:userID,nonce:nonce},error:function(jqXHR,textStatus,errorThrown){if(false===jqXHR.responseJSON.success){let errMsg=jQuery('#2fa-error-msg');if(errMsg.length){errMsg.remove();}
jQuery('<span id="2fa-error-msg" style="color:red;">'+jqXHR.responseJSON.data[0].message+'</span>').insertAfter(inputUsed);}},complete:function(data){},success:function(data){let errMsg=jQuery('#2fa-error-msg');if(errMsg.length){errMsg.remove();}
if(updateBtnText){jQuery(thisBtn).find('span').fadeTo(100,0,function(){jQuery(thisBtn).find('span').delay(100);jQuery(thisBtn).find('span').text(wp2faWizardData.codeReSentText);jQuery(thisBtn).find('span').fadeTo(100,1);});setTimeout(function(){jQuery(thisBtn).find('span').fadeTo(100,0,function(){jQuery(thisBtn).find('span').delay(100);jQuery(thisBtn).find('span').text(originalBtnText);jQuery(thisBtn).find('span').fadeTo(100,1);});},2500);}}});});jQuery(document).on('change','[name="wp_2fa_enabled_methods"]',function(event){var step=jQuery('[name="wp_2fa_enabled_methods"]:checked').val();if(undefined===step){jQuery('.2fa-choose-method[data-name]').removeAttr('data-next-step');}else{jQuery('.2fa-choose-method[data-name]').attr('data-next-step',`2fa-wizard-${step}`);}});jQuery('body').on('click','.button[data-name="next_step_setting_modal_wizard"]',function(e){e.preventDefault;var nextStep=jQuery(this).attr('data-next-step');if(undefined===nextStep){var nextStep='2fa-wizard-'+jQuery('[name="wp_2fa_enabled_methods"]:checked').val();jQuery('.2fa-choose-method[data-name]').attr('data-next-step',`2fa-wizard-${nextStep}`);}
if(nextStep){const currentSubStep=jQuery(this).parent().parent().find('.active').not('.step-setting-wrapper');const nextSubStep=jQuery(`#${nextStep}`);jQuery(this).parent().parent().find('.active').not('.step-setting-wrapper').removeClass('active');jQuery('.wizard-step.active').removeClass('active');jQuery(nextSubStep).addClass('active');var in_el=jQuery(nextSubStep).find("input[type=text]");if(!in_el.length){in_el=jQuery(nextSubStep).find("input[type=password]");}
if(in_el.length){in_el.focus();}}else{const currentSubStep=jQuery(this).parent().parent().find('.active').not('.step-setting-wrapper');const nextSubStep=jQuery(currentSubStep).next();jQuery('.wizard-step.active').removeClass('active');jQuery(nextSubStep).addClass('active');}
jQuery('.inline-helper').remove();});jQuery('body').on('click','.button[data-trigger-generate-backup-codes]',function(e){e.preventDefault();const actionToRun='wp2fa_run_ajax_generate_json';const nonceValue=jQuery(this).attr('data-nonce');const currentSubStep=jQuery(this).closest('.step-setting-wrapper.active');const nextSubStep=jQuery(currentSubStep).nextAll('div:not(.hidden)').filter(':first');jQuery(currentSubStep).removeClass('active');jQuery(nextSubStep).addClass('active');updateStepTitles();jQuery.ajax({type:'POST',dataType:'json',url:wp2faData.ajaxURL,data:{action:actionToRun,_wpnonce:nonceValue},complete:function(data){jQuery('#backup-codes-wrapper').slideUp(0);jQuery('.wp2fa-modal.is-open #backup-codes-wrapper, .wp2fa-setup-content #backup-codes-wrapper').val('');var codes=jQuery.parseJSON(data.responseText);var codes=codes.data['codes'];jQuery.each(codes,function(index,value){var oldValue=jQuery('.wp2fa-modal.is-open #backup-codes-wrapper, .wp2fa-setup-content #backup-codes-wrapper').val();var counter=index+1;jQuery('.wp2fa-modal.is-open #backup-codes-wrapper, .wp2fa-setup-content #backup-codes-wrapper').val(oldValue+counter+': '+`${value} \n`);});jQuery('#backup-codes-wrapper').slideDown(500);jQuery('.close-wizard-link').text(wp2faWizardData.readyText).fadeIn(50);}},);});jQuery('body').on('click','.button[data-trigger-reset-key]',function(e){e.preventDefault();if(jQuery('.qr-code-wrapper').length){jQuery('.qr-code-wrapper').addClass('regenerating');}
var doReload=jQuery(this).attr('data-trigger-reset-key');const thisButton=jQuery(this);const actionToRun='regenerate_authentication_key';const nonceValue=jQuery(this).attr('data-nonce');const userID=jQuery(this).attr('data-user-id');jQuery.ajax({type:'POST',dataType:'json',url:wp2faData.ajaxURL,data:{action:actionToRun,_wpnonce:nonceValue,user_id:userID},complete:function(data){if(jQuery('.change-2fa-confirm.hidden').length){jQuery('.change-2fa-confirm.hidden').trigger('click');}
if(jQuery('.app-key').length){jQuery('#wp-2fa-totp-qrcode').attr('src',data.responseJSON.data['qr']);jQuery('.app-key').val(data.responseJSON.data['key']);jQuery('[name="wp-2fa-totp-key"]').val(data.responseJSON.data['key']);setTimeout(function(){jQuery('.qr-code-wrapper').removeClass('regenerating');},500);}}},);});jQuery('body').on('click','.button[data-trigger-backup-code-email]',function(e){e.preventDefault();const thisButton=jQuery(this);const actionToRun='send_backup_codes_email';const nonceValue=jQuery(this).attr('data-nonce');const userID=jQuery(this).attr('data-user-id');const codesWrapper=JSON.stringify(jQuery('.active #backup-codes-wrapper').val());jQuery.ajax({type:'POST',dataType:'json',url:wp2faData.ajaxURL,data:{action:actionToRun,_wpnonce:nonceValue,user_id:userID,codes:codesWrapper},complete:function(data){jQuery('.button[data-trigger-backup-code-email]').text(wp2faWizardData.backupCodesSent).attr('value',wp2faWizardData.backupCodesSent);}},);});jQuery('body').on('click','.click-to-copy',function(e){var copyText=jQuery(this).prev();var{__}=window.wp.i18n;copyText.select();if(typeof copyText.setSelectionRange!=="undefined"){copyText.setSelectionRange(0,99999);}
navigator.clipboard.writeText(copyText[0].value);jQuery(this).addClass('done').html(window.wp.i18n.__('Copied','wp-2fa'));});jQuery('body').on('click','.button[data-trigger-backup-code-copy]',function(e){e.preventDefault();var{__}=window.wp.i18n;var copyText=jQuery('.active #backup-codes-wrapper');copyText.select();if(typeof copyText.setSelectionRange!=="undefined"){copyText.setSelectionRange(0,99999);}
navigator.clipboard.writeText(copyText[0].value);jQuery(this).addClass('done').html(window.wp.i18n.__('Copied','wp-2fa'));});jQuery('body').on('click','.button[data-trigger-backup-code-download]',function(e){e.preventDefault();const userName=jQuery(this).attr('data-user');const websiteURL=jQuery(this).attr('data-website-url');const preamble=`${wp2faWizardData.codesPreamble} ${userName} on the website ${websiteURL}:\n\n`;var codesWrapper=jQuery('.active #backup-codes-wrapper').val().split(' ').join('\n');download('backup_codes.txt',preamble+codesWrapper);});jQuery('body').on('click','.button[data-trigger-print]',function(e){e.preventDefault();const userName=jQuery(this).attr('data-user-id');const websiteURL=jQuery(this).attr('data-website-url');const preamble=`${wp2faWizardData.codesPreamble} ${userName} on the website ${websiteURL}:\n\n`;const divToPrint=jQuery('.active #backup-codes-wrapper').val();const newWin=window.open('','Print-Window');newWin.document.open();newWin.document.write(`<html><body onload="window.print()">${preamble}</br></br>${divToPrint}</body></html>`);newWin.document.close();setTimeout(function(){newWin.close();},10);});function download(filename,text){const element=document.createElement('a');element.setAttribute('href',`data:text/plain;charset=utf-8,${encodeURIComponent( text )}`);element.setAttribute('download',filename);element.style.display='none';document.body.appendChild(element);element.click();document.body.removeChild(element);}
jQuery(document).on('click','#custom-email-address',function(){jQuery('#use_custom_email').prop('checked',true);});jQuery(document).on('click','#custom-oob-email-address',function(){jQuery('#use_custom_oob_email').prop('checked',true);});jQuery(document).on('click','[data-check-on-click]',function(){const thingToCheck=jQuery(this).attr('data-check-on-click');jQuery(thingToCheck).prop('checked',true);});jQuery(document).on('click','[data-trigger-submit-form]',function(e){e.preventDefault();const thingToSubmit=jQuery(this).attr('data-trigger-submit-form');jQuery('.change-2fa-confirm').trigger('click');});jQuery(document).on('click','[data-reload]',function(e){removeShowParam();});window.removeShowParam=function(){let url=new URL(location.href);let params=new URLSearchParams(url.search);params.delete('show');location.replace(`${location.pathname}?${params}`);}
jQuery('[name="wp_2fa_settings[enforcement-policy]"]').on("input",function(){if(jQuery('input[name="wp_2fa_settings[enforcement-policy]"]:checked').val()!=='do-not-enforce'){jQuery('[data-step-title="Exclude users"]').removeClass('hidden');updateStepTitles();}else{jQuery('[data-step-title="Exclude users"]').addClass('hidden');updateStepTitles();}});jQuery('body').on('click','.iti__flag-container',function(e){var isExpand=(jQuery('.iti__selected-flag').attr('aria-expanded'))?'expand-panel':'';jQuery(this).closest('.wizard-step.active').toggleClass(isExpand);});jQuery('body').on('click','.step-setting-wrapper #all-users, .step-setting-wrapper #certain-roles-only',function(e){jQuery('.step-setting-wrapper.active .continue-wizard').removeClass('hidden');jQuery('.step-setting-wrapper.active .save-wizard').addClass('hidden');});jQuery('body').on('click','.step-setting-wrapper #do-not-enforce',function(e){jQuery('.step-setting-wrapper.active .continue-wizard').addClass('hidden');jQuery('.step-setting-wrapper.active .save-wizard').removeClass('hidden');});});window.onresize=function(){checkWizardOffset();}
function checkWizardOffset(){var elem=document.querySelector('.setup-wizard-wrapper');if(elem){var bounding=elem.getBoundingClientRect();if(bounding.top<0){var clientHeight=bounding.height / 2;elem.style.cssText+='top: '+clientHeight+'px';}}}
window.wp2fa_fireWizard=function(){jQuery('.verification-response span').remove();jQuery('#configure-2fa .wizard-step.active, #configure-2fa .step-setting-wrapper.active').removeClass('active');jQuery('#configure-2fa .wizard-step:first-of-type, #configure-2fa .step-setting-wrapper:first-of-type').addClass('active');jQuery('.modal__content input:not([type="radio"]):not([type="hidden"])').not('.app-key').val('');MicroModal.show('configure-2fa');if(jQuery('input#basic').is(':visible')){jQuery('input#basic').trigger("click");}else{if(jQuery('input#geek').is(':visible')){jQuery('input#geek').trigger("click");}else{if(jQuery('input#oob').length){jQuery('input#oob').trigger("click");}else if(jQuery('input#authy').length){jQuery('input#authy').trigger("click");}else if(jQuery('input#twilio').length){jQuery('input#twilio').trigger("click");}}}
jQuery('[name="wp_2fa_enabled_methods"]').change();if(1===jQuery('.wizard-step.active .option-pill').length){jQuery('#configure-2fa .wizard-step:first-of-type, #configure-2fa input:radio[name=wp_2fa_enabled_methods]:first').attr("checked",true);setTimeout(()=>{jQuery('.wp-2fa-button-primary.2fa-choose-method').trigger("click");},100)}else{jQuery('#configure-2fa .wizard-step:first-of-type, #configure-2fa input:radio[name=wp_2fa_enabled_methods]:first').prop("checked",true);jQuery('[name="wp_2fa_enabled_methods"]').change();jQuery('#configure-2fa .wizard-step:first-of-type, #configure-2fa input:radio[name=wp_2fa_enabled_methods]:first').trigger("click");}};
}
catch(e){console.error("An error has occurred common.js: "+e.stack);}
