!function(e){const a=e("#learndash_settings_paypal_checkout_settings_paypal_checkout"),n=e(".ld-paypal-checkout__button--connect",a);function t(n,t){e(".ld-paypal-checkout__error",a).remove(),a.prepend('<div class="ld-paypal-checkout__error"></div>');const o=e(".ld-paypal-checkout__error",a);o.text(t).dialog({modal:!0,draggable:!1,resizable:!1,dialogClass:"ld-paypal-checkout__error-dialog",title:n,buttons:[{text:wp.i18n.__("OK","learndash"),click:()=>{o.dialog("close")},class:"button button-primary"}]}).dialog("open")}function o(n,t,o,c){e(".ld-paypal-checkout__confirm-action",a).remove(),a.prepend('<div class="ld-paypal-checkout__confirm-action"></div>');const s=e(".ld-paypal-checkout__confirm-action",a);s.text(t).dialog({modal:!0,draggable:!1,resizable:!1,width:"40%",title:n,buttons:[{text:wp.i18n.__("Cancel","learndash"),click:()=>{s.dialog("close")},class:"button button-secondary"},{text:o,click:c,class:"button button-primary"}]}).dialog("open")}e("input, select, textarea",a).on("change",function(){a.addClass("settings-not-saved"),n.attr("href","")}),n.length&&e.ajax({url:learndash.paypal_checkout.admin.endpoints.signup_url,method:"GET",data:{account_country:learndash.paypal_checkout.admin.account_country,is_sandbox:learndash.paypal_checkout.admin.is_sandbox,is_setup_wizard:learndash.paypal_checkout.admin.is_setup_wizard},beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",wpApiSettings.nonce),e.setRequestHeader("Learndash-Experimental-Rest-Api","Allow")},success:e=>{n.attr("href",e.data.signup_url+"&displayMode=minibrowser")},error:()=>{t(wp.i18n.__("Unable to generate a signup link","learndash"),wp.i18n.__("An error occurred while connecting your PayPal account. Try updating your settings and try again.","learndash"))}}),n.on("click",function(e){a.hasClass("settings-not-saved")&&(e.preventDefault(),t(wp.i18n.__("Unsaved changes","learndash"),wp.i18n.__("Before you can connect your PayPal account, you need to save your settings.","learndash")))}),e(".ld-paypal-checkout__button--disconnect",a).on("click",function(a){a.preventDefault(),o(wp.i18n.__("Are you sure?","learndash"),wp.i18n.__("Disconnecting your PayPal account will prevent you from offering PayPal at the checkout on your website. Do you wish to continue?","learndash"),wp.i18n.__("Disconnect","learndash"),()=>{e.ajax({url:learndash.paypal_checkout.admin.endpoints.disconnect,method:"DELETE",dataType:"json",contentType:"application/json",data:JSON.stringify({confirm_disconnect:!0}),beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",wpApiSettings.nonce),e.setRequestHeader("Learndash-Experimental-Rest-Api","Allow")},success:()=>{window.location.href=learndash.paypal_checkout.admin.settings_url+"&disconnected=1"}})})}),e(".ld-paypal-checkout__button--reconnect",a).on("click",function(a){a.preventDefault(),o(wp.i18n.__("Are you sure?","learndash"),wp.i18n.__("This action will refresh the PayPal Checkout connection and webhooks.","learndash"),wp.i18n.__("Reconnect","learndash"),()=>{e.ajax({url:learndash.paypal_checkout.admin.endpoints.reconnect,method:"POST",dataType:"json",contentType:"application/json",data:JSON.stringify({is_sandbox:learndash.paypal_checkout.admin.is_sandbox}),beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",wpApiSettings.nonce),e.setRequestHeader("Learndash-Experimental-Rest-Api","Allow")},success:()=>{window.location.href=learndash.paypal_checkout.admin.settings_url+"&reconnected=1"},error:()=>{t(wp.i18n.__("Unable to reconnect","learndash"),wp.i18n.__("An error occurred while reconnecting your PayPal account. Try updating your settings and try again.","learndash"))}})})})}(jQuery),window.ldPaypalCheckoutOnboardComplete=function(e,a){jQuery.ajax({url:learndash.paypal_checkout.admin.endpoints.access_token,method:"POST",dataType:"json",contentType:"application/json",data:JSON.stringify({shared_id:a,auth_code:e,is_sandbox:learndash.paypal_checkout.admin.is_sandbox}),beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",wpApiSettings.nonce),e.setRequestHeader("Learndash-Experimental-Rest-Api","Allow")}})};