"use strict";jQuery(document).ready((function($){var e=$("#setup-2fa"),a=$("#admin-2fa-qr-container"),n=$("#admin-qr-code-img"),i=$("#admin-qr-code-err"),r=$("#admin-qr-spinner"),o=$("#admin-generate-qr"),s=$("#admin-verify-2fa"),t=$("#admin-2fa-code"),c=$("#admin-2fa-verify-msg"),d=$("#reset-2fa");function f(){e.prop("disabled",!0),o.prop("disabled",!0),r.addClass("is-active"),i.empty(),a.show(),$.ajax({url:admin_2fa_config.ajaxurl,type:"POST",data:{action:"secnin_admin_generate_qr",user_id:admin_2fa_config.user_id,nonce:admin_2fa_config.nonce},success:function(a){e.prop("disabled",!1),o.prop("disabled",!1),r.removeClass("is-active"),a.success&&a.data&&a.data.qr_code?(i.empty(),n.attr("src",a.data.qr_code),o.show(),a.data.secret&&($("#admin-secret-key").val(a.data.secret),$("#admin-secret-container").show())):i.html('<p class="error">'+(a.data&&a.data.message?a.data.message:admin_2fa_config.messages.qr_error)+"</p>")},error:function(){e.prop("disabled",!1),o.prop("disabled",!1),r.removeClass("is-active"),i.html('<p class="error">'+admin_2fa_config.messages.network_error+"</p>")}})}function m(e,a){var n="notice notice-"+("error"===a?"error":"success"===a?"success":"info");c.html('<div class="'+n+'"><p>'+e+"</p></div>")}e.on("click",(function(e){e.preventDefault(),f()})),o.on("click",(function(e){e.preventDefault(),f()})),d.on("click",(function(e){e.preventDefault(),confirm(admin_2fa_config.messages.reset_confirm||"Are you sure you want to reset 2FA for this user?")&&(d.prop("disabled",!0),m("Resetting 2FA...","info"),$.ajax({url:admin_2fa_config.ajaxurl,type:"POST",data:{action:"secnin_admin_reset_2fa",user_id:admin_2fa_config.user_id,nonce:admin_2fa_config.nonce},success:function(e){e.success?(m(e.data.message,"success"),setTimeout((function(){window.location.reload()}),2e3)):(d.prop("disabled",!1),m(e.data.message||admin_2fa_config.messages.unknown_error,"error"))},error:function(){d.prop("disabled",!1),m(admin_2fa_config.messages.network_error,"error")}}))})),t.on("input",(function(){var e=$(this).val();e=(e=e.replace(/\D/g,"")).slice(0,6),$(this).val(e),s.prop("disabled",6!==e.length)})),s.on("click",(function(e){e.preventDefault();var a=t.val();6===a.length?function(e){s.prop("disabled",!0),t.prop("disabled",!0),m(admin_2fa_config.messages.verifying,"info"),$.ajax({url:admin_2fa_config.ajaxurl,type:"POST",data:{action:"secnin_admin_verify_2fa",user_id:admin_2fa_config.user_id,nonce:admin_2fa_config.nonce,code:e},success:function(e){e.success?(m(e.data.message,"success"),setTimeout((function(){window.location.reload()}),2e3)):(s.prop("disabled",!1),t.prop("disabled",!1),m(e.data.message||admin_2fa_config.messages.invalid_code,"error"))},error:function(){s.prop("disabled",!1),t.prop("disabled",!1),m(admin_2fa_config.messages.network_error,"error")}})}(a):m("Please enter a valid 6-digit code.","error")})),$("#admin-copy-secret").on("click",(function(e){e.preventDefault();var a=document.getElementById("admin-secret-key");a.select(),a.setSelectionRange(0,99999);try{document.execCommand("copy");var n=$(this),i=n.text();n.text("Copied!"),setTimeout((function(){n.text(i)}),2e3)}catch(e){navigator.clipboard.writeText(a.value).then((function(){var e=$("#admin-copy-secret"),a=e.text();e.text("Copied!"),setTimeout((function(){e.text(a)}),2e3)})).catch((function(){alert("Failed to copy secret key. Please select and copy manually.")}))}}))}));