var e=class{constructor(e,t){this.form=e,this.data=t.data,this.retryCount=0,this.maxRetries=8}init(){if(typeof paypal>`u`){if(document.querySelector(`script[src*="paypal.com/sdk/js"]`)){if(this.retryCount>=this.maxRetries){this.form.find(`.buymecoffee_pay_methods`)?.parent().prepend(`<p style='color: red;'>PayPal SDK failed to initialize. Please verify your PayPal Client ID and try again.</p>`);return}this.retryCount++;let e=Math.min(1500,200*this.retryCount);setTimeout(()=>this.init(),e)}else console.error(`PayPal SDK script not found in DOM. Please check PayPal configuration.`),this.form.find(`.buymecoffee_pay_methods`)?.parent().prepend(`<p style='color: red;'>PayPal SDK failed to load. Please check your PayPal Client ID configuration.</p>`);return}this.form.find(`.wpm_submit_button, .buymecoffee_pay_method`).hide();let e=jQuery(`<div class='buymecoffee_paypal_button_wrap' style='padding: 0px;'></div>`);paypal.Buttons({fundingSource:paypal.FUNDING.PAYPAL,style:{shape:`pill`,layout:`vertical`,label:`paypal`,size:`responsive`,disableMaxWidth:!0},createOrder:(e,t)=>t.order.create({purchase_units:[this.data.purchase_units]}),onApprove:e=>(this.form.find(`.buymecoffee_paypal_button_wrap`).hide(),this.form.find(`.complete_payment_instruction`).html(`Please wait, payment is being confirmed...`),jQuery.post(window.buymecoffee_general.ajax_url,{action:`buymecoffee_payment_confirmation_paypal`,buymecoffee_nonce:window.buymecoffee_general?.buymecoffee_nonce||``,hash:this.data.hash,charge_id:e.orderID}).then(()=>{let e=this.getSafeRedirectUrl(this.data?.confirmation_url);if(!e)throw Error(`Unsafe confirmation URL blocked.`);window.location=e}).catch(e=>{let t=e?.responseJSON?.data?.message||`Payment could not be confirmed. Please try again.`;alert(t),this.form.find(`.buymecoffee_paypal_button_wrap`).show(),this.form.find(`.complete_payment_instruction`).html(`Please complete your donation with PayPal 👇`)})),onError:function(e){alert(`An error occurred: `+e)}}).render(e[0]),this.form.find(`.buymecoffee_form_submit_wrapper, .buymecoffee_no_signup, .buymecoffee_input_content, .buymecoffee_payment_input_content, .buymecoffee_payment_item`).hide(),this.form.find(`.buymecoffee_pay_methods`)?.parent().append(e),this.form.prepend(`<p class='complete_payment_instruction'>Please complete your donation with PayPal 👇</p>`)}getSafeRedirectUrl(e){if(!e)return null;try{let t=new URL(e,window.location.origin);return![`http:`,`https:`].includes(t.protocol)||t.origin!==window.location.origin?null:t.toString()}catch{return null}}};window.addEventListener(`buymecoffee_payment_next_action_paypal`,function(t){new e(t.detail.form,t.detail.response).init()});