(()=>{var e={1669:e=>{"use strict";e.exports=jQuery}},n={};!function(e){"use strict";const n={init:function(){this.bindEvents()},bindEvents:function(){e(document).on("click","#edd-square-connect",this.initiateConnection.bind(this)),e(document).on("click","#edd-square-reconnect",this.reconnectSquare.bind(this)),e(document).on("click","#edd-square-disconnect",this.disconnectSquare.bind(this)),e(document).on("click","#edd-square-register-webhooks",this.registerWebhooks.bind(this)),edd_square_admin.is_connected||e("#submit").hide()},initiateConnection:function(n){n.preventDefault();const d=edd_square_admin.is_test_mode?"test":"live",t=e(n.target),a=t.text();t.prop("disabled",!0).text(edd_square_admin.i18n.connecting),e.ajax({url:edd_square_admin.ajax_url,type:"POST",data:{action:"edd_square_initiate_connection",mode:d,nonce:edd_square_admin.nonce},success:function(e){e.success?window.location.href=e.data.oauth_url:alert(e.data.message||edd_square_admin.i18n.connection_error)},error:function(){alert(edd_square_admin.i18n.connection_error),t.prop("disabled",!1).text(a)}})},reconnectSquare:function(n){n.preventDefault();const d=e(n.target).data("mode")||"test",t=e(n.target),a=t.text();t.addClass("disabled").text(edd_square_admin.i18n.reconnecting),e.ajax({url:edd_square_admin.ajax_url,type:"POST",data:{action:"edd_square_initiate_connection",mode:d,nonce:edd_square_admin.nonce},success:function(e){e.success?window.location.href=e.data.oauth_url:alert(e.data.message||edd_square_admin.i18n.connection_error)},error:function(){alert(edd_square_admin.i18n.connection_error),t.removeClass("disabled").text(a)}})},disconnectSquare:function(n){if(n.preventDefault(),n.stopPropagation(),!confirm(edd_square_admin.i18n.disconnect_confirm))return;const d=e(n.target),t=d.text();d.addClass("disabled").text(edd_square_admin.i18n.disconnecting),e.ajax({url:edd_square_admin.ajax_url,type:"POST",data:{action:"edd_square_disconnect",nonce:edd_square_admin.nonce},success:function(e){e.success?(alert(e.data.message),window.location.reload()):alert(e.data.message||edd_square_admin.i18n.connection_error)},error:function(e){alert(e.responseJSON.data||edd_square_admin.i18n.connection_error),d.removeClass("disabled").text(t)}})},registerWebhooks:function(n){n.preventDefault();const d=e(n.target).closest(".edd-promo-notice__actions"),t=e(n.target).data("nonce"),a=e("#edd-square-personal-access-token").val(),i=e("#edd-square-webhooks-spinner"),s=e("#edd-square-webhooks-message");if(s.html("").addClass("edd-hidden"),i.removeClass("edd-hidden"),d.find("button").prop("disabled",!0),!a||!t)return d.find("#edd-square-webhooks-message").text("Missing required fields. Refresh the page and try again.").show(),d.find("button").prop("disabled",!1),void i.addClass("edd-hidden");e.ajax({url:edd_square_admin.ajax_url,type:"POST",data:{action:"edd_square_register_webhooks",nonce:t,token:a}}).success((function(e){s.html(e.data).removeClass("edd-hidden"),i.addClass("edd-hidden"),setTimeout((function(){window.location.reload()}),3e3)})).fail((function(e){s.html(e.responseJSON.data).removeClass("edd-hidden")})).always((function(){d.find("button").prop("disabled",!1),i.addClass("edd-hidden")}))}};e(document).ready((function(){"undefined"!=typeof edd_square_admin&&n.init()})),window.eddSquareAdmin=n}(function d(t){var a=n[t];if(void 0!==a)return a.exports;var i=n[t]={exports:{}};return e[t](i,i.exports,d),i.exports}(1669))})();