(()=>{"use strict";const e=window.React,t=function({paymentMethodConfigurationId:t,eventRegistration:n}){const{onCheckoutSuccess:o,onCheckoutValidation:a}=n,[r,c]=(0,e.useState)(!0),i=`payment-method-${t}`;let s=window.IframeCheckoutHandler(t);const d=(0,e.useCallback)((()=>{s.create(i),c(!1)}),[t,i]);return(0,e.useEffect)((()=>{document.getElementById(i)&&d();const e=o((()=>new Promise((e=>{s.submit(),setTimeout((function(){e(!1)}),3e4)})))),t=a((()=>{let e=new Promise((e=>{s.setValidationCallback((t=>{void 0!==t.success?e(t.success):(console.error("Validation was not successful"),e(!1))}))}));return s.validate(),e}));return()=>{e(),t()}}),[d,i,o,a]),(0,e.createElement)("div",null,r&&(0,e.createElement)("div",null,"Loading payment method..."),(0,e.createElement)("div",{id:i}))},n=function({paymentMethodConfigurationId:t,eventRegistration:n}){const{onCheckoutSuccess:o}=n;(0,e.useEffect)((()=>{const e=o((()=>new Promise(((e,n)=>{window.LightboxCheckoutHandler.startPayment(t,(function(t,o){!t||t.error?n(t):e(t)}))})).catch((e=>{console.error(e)}))));return()=>{e()}}),[o,t])},o=function({paymentMethodConfigurationId:e,paymentPageUrl:t,eventRegistration:n}){const{onCheckoutSuccess:o}=n};function a({label:t,src:n,alt:o,width:a}){return(0,e.createElement)("div",null," ",t," ",(0,e.createElement)("img",{src:n,alt:o,width:a})," ")}const r=window.wc.wcBlocksRegistry,c=async()=>{try{const e=new URLSearchParams;e.append("action","get_payment_methods"),e.append("weareplanet_nonce",window.weareplanet_block_params?.weareplanet_nonce||""),e.append("updateTransaction","1");const t=await fetch(wp.apiFetch.nonceEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e});if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);const n=await t.json();if(!n)throw new Error("No payment methods found");return n}catch(e){console.error("Error fetching payment methods:",e)}},i=async c=>{c.forEach((c=>{const i=(()=>{switch(c.integration_mode){case"iframe":return(0,e.createElement)(t,{paymentMethodConfigurationId:c.configuration_id});case"lightbox":return(0,e.createElement)(n,{paymentMethodConfigurationId:c.configuration_id});default:return(0,e.createElement)(o,{paymentMethodConfigurationId:c.configuration_id})}})(),s=function(e){const t=e.match(/src="([^"]+)"/),n=e.match(/alt="([^"]*)"/),o=e.match(/width="([^"]+)"/);return{src:t?t[1]:"",alt:n?n[1]:"",width:o?o[1]:""}}(c.icon);(0,r.registerPaymentMethod)({name:c.name,label:(0,e.createElement)(a,{label:c.label,...s}),content:i,edit:(0,e.createElement)("div",null,c.description),ariaLabel:c.ariaLabel,supports:{features:c.supports},canMakePayment:()=>Promise.resolve(c.isActive)})}))};if(document.body.classList.contains("woocommerce-checkout")){const e=document.getElementById("weareplanet-payment-methods")?.getAttribute("data-json");if(e)try{const t=JSON.parse(e);i(t)}catch(e){console.error("Error parsing JSON from HTML:",e)}else(async()=>{try{const e=await c();i(e)}catch(e){console.error("Error initializing payment methods:",e)}})();!function(){const e=window.fetch;window.fetch=async(...t)=>{const n=await e(...t);try{const e=t[0];if("string"==typeof e&&e.includes("/wc/store/v1/batch")){const e=t[1]?.body?JSON.parse(t[1].body):null;if(e&&e.requests&&Array.isArray(e.requests)&&e.requests.some((e=>"/wc/store/v1/cart/update-customer"===e.path))){const e=await c(),t=(0,r.getPaymentMethods)();e.forEach((e=>{var n;const o={...null!==(n=t[e.name])&&void 0!==n&&n,canMakePayment:()=>e.isActive};(0,r.registerPaymentMethod)(o)}))}}}catch(e){console.error("Error handling batch response:",e)}return n}}()}})();