(function(){jQuery(function(t){var e,n,a;return a=null!=(n=window.wc_payment_gateway_token_editor)?n:{},t(".sv_wc_payment_gateway_token_editor").each(function(){return 0===t(this).find("tr.token").length?t(this).find("tr.no-tokens").show():t(this).find("tr.no-tokens").hide()}),t(".sv_wc_payment_gateway_token_editor").on("click",'.button[data-action="remove"]',function(n){var o,r,s;if(n.preventDefault(),confirm(a.actions.remove_token.ays))return((r=t(this).closest("table")).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),r.find(".error").remove(),(s=t(this).closest("tr")).hasClass("new-token"))?(r.unblock(),s.remove()):(o={action:"wc_payment_gateway_"+r.data("gateway-id")+"_admin_remove_payment_token",user_id:t(this).data("user-id"),token_id:t(this).data("token-id"),security:a.actions.remove_token.nonce},t.post(a.ajax_url,o).done(n=>n.success?(t(s).remove(),0===r.find("tr.token").length)?r.find("tr.no-tokens").show():void 0:e(r,n.data)).fail((t,n,a)=>e(r,n+": "+a)).always(()=>r.unblock()))}),t("table.sv_wc_payment_gateway_token_editor").on("click",'.button[data-action="add-new"]',function(e){var n,o,r,s;return e.preventDefault(),(s=t(this).closest("table")).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),o=(n=s.find("tbody.tokens")).find("tr.token").length,r={action:"wc_payment_gateway_"+s.data("gateway-id")+"_admin_get_blank_payment_token",index:o+1,security:a.actions.add_token.nonce},t.post(a.ajax_url,r,function(t){return!0===t.success&&n.append(t.data),s.find("tr.no-tokens").hide(),s.unblock()})}),t("table.sv_wc_payment_gateway_token_editor").on("click",'.button[data-action="refresh"]',function(n){var o,r,s;return n.preventDefault(),(s=t(this).closest("table")).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),s.find(".error").remove(),(o=s.find("tbody.tokens")).find("tr.token").length,r={action:"wc_payment_gateway_"+s.data("gateway-id")+"_admin_refresh_payment_tokens",user_id:t(this).data("user-id"),security:a.actions.refresh.nonce},t.post(a.ajax_url,r).done(t=>t.success?null!=t.data?(s.find("tr.no-tokens").hide(),o.html(t.data)):(o.empty(),s.find("tr.no-tokens").show()):e(s,t.data)).fail((t,n,a)=>e(s,n+": "+a)).always(()=>s.unblock())}),t("table.sv_wc_payment_gateway_token_editor").on("click",'.sv-wc-payment-gateway-token-editor-action-button[data-action="save"]',function(e){var n,o,r,s;return n=(o=t(this).closest("table")).find("tfoot th"),o.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),n.find(".error, .success").remove(),s=o.find('tbody.tokens tr.token input[type="text"]'),r=!1,s.each(function(s){var i,c,d;if(t(this).removeClass("error"),d=t(this).val(),c=t(this).prop("required"),i=t(this).attr("pattern"),(c||d)&&(!d.match(i)||c&&!d))return e.preventDefault(),t(this).addClass("error"),r||(n.prepend('<span class="error">'+a.actions.save.error+"</span>"),t(this).focus(),r=!0),o.unblock()})}),e=function(t,e,n=""){return console.error(e),n||(n=a.i18n.general_error),t.find("th.actions").prepend('<span class="error">'+n+"</span>")}})}).call({});
//# sourceMappingURL=sv-wc-payment-gateway-token-editor.js.map
