(()=>{"use strict";var e={1669:e=>{e.exports=jQuery}},t={};function n(o){var a=t[o];if(void 0!==a)return a.exports;var s=t[o]={exports:{}};return e[o](s,s.exports,n),s.exports}function o(e){const t=e.target;if(!t||"INPUT"!==t.nodeName||"checkbox"!==t.type)return;const n=t.dataset.setting;if(!n||!t.dataset.nonce)return;t.disabled=!0;const o=t.checked,a=new URLSearchParams;a.append("action","edd_toggle_ajax_setting"),a.append("nonce",t.dataset.nonce),a.append("setting",n),a.append("value",o?"1":"0"),fetch(ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},credentials:"same-origin",body:a}).then((function(e){if(!e.ok)throw new Error("Network response was not ok");return e.json()})).then((function(e){if(!e?.success)throw new Error(e?.data?.message||"Save failed");document.dispatchEvent(new CustomEvent("eddSettingToggled",{detail:{setting:n,value:o,...e.data}}))})).catch((function(){t.checked=!o})).finally((function(){t.disabled=!1}))}var a=n(1669),s=n(1669);const r={init:function(){this.revoke_api_key(),this.regenerate_api_key(),this.create_api_key(),this.recount_stats(),this.enable_toggles()},revoke_api_key:function(){a(document.body).on("click",".edd-revoke-api-key",(function(e){return confirm(edd_vars.revoke_api_key)}))},regenerate_api_key:function(){a(document.body).on("click",".edd-regenerate-api-key",(function(e){return confirm(edd_vars.regenerate_api_key)}))},create_api_key:function(){a(document.body).on("submit","#api-key-generate-form",(function(e){const t=a('input[type="text"][name="user_id"]');t.css("border-color","#ddd");const n=t.val();if(n.length<1||0===n)return t.css("border-color","#ff0000"),!1}))},recount_stats:function(){a(document.body).on("change","#recount-stats-type",(function(){const e=a("#edd-tools-recount-form"),t=a("option:selected",this).data("type"),n=a("#recount-stats-submit"),o=a("#tools-product-dropdown");e.find(".notice-wrap").remove(),n.attr("disabled",!1).removeClass("updated-message"),o.hide(),a(".edd-recount-stats-descriptions span").hide(),"recount-download"===t?(o.show(),o.find(".edd-select-chosen").css("width","auto")):"reset-stats"===t?(e.append('<div class="notice-wrap"></div>'),e.find(".notice-wrap").html('<div class="notice notice-warning"><p><input type="checkbox" id="confirm-reset" name="confirm_reset_store" value="1" /> <label for="confirm-reset">'+edd_vars.reset_stats_warn+"</label></p></div>"),a("#recount-stats-submit").attr("disabled",!0)):(o.hide(),o.val(0)),a("#"+t).show()})),a(document.body).on("change","#confirm-reset",(function(){a(this).is(":checked")?a("#recount-stats-submit").attr("disabled",!1):a("#recount-stats-submit").attr("disabled",!0)})),a("#edd-tools-recount-form").submit((function(e){e.preventDefault();const t=a("#recount-stats-type").val(),n=a(this),o=a("option:selected",this).data("type");if("reset-stats"===o){if(a("#confirm-reset").is(":checked"))return!0;r=!0}n.find(".notice-wrap").remove(),n.append('<div class="notice-wrap"></div>');var s=n.find(".notice-wrap"),r=!1;if(null!==t&&0!==t||(s.html('<div class="updated error"><p>'+edd_vars.batch_export_no_class+"</p></div>"),r=!0),"recount-download"===o&&0===a('select[name="download_id"]').val()&&(s.html('<div class="updated error"><p>'+edd_vars.batch_export_no_reqs+"</p></div>"),r=!0),r)return n.find("button:disabled").attr("disabled",!1).removeClass("updated-message"),!1}))},enable_toggles:function(){document.addEventListener("change",o)}};s(document).ready((function(e){r.init()}))})();