(()=>{"use strict";const e=window.React,t=function({paymentMethodConfigurationId:t,eventRegistration:n}){const{onCheckoutSuccess:o,onCheckoutValidation:r}=n,[a,c]=(0,e.useState)(!0),i=`payment-method-${t}`;let s=window.IframeCheckoutHandler(t);const u=(0,e.useCallback)((()=>{s.create(i),c(!1)}),[t,i]);return(0,e.useEffect)((()=>{document.getElementById(i)&&u();const e=o((()=>new Promise((e=>{s.submit(),setTimeout((function(){e(!1)}),3e4)})))),t=r((()=>{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()}}),[u,i,o,r]),(0,e.createElement)("div",null,a&&(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 r({label:t,src:n,alt:o,width:r}){return(0,e.createElement)("div",null," ",t," ",(0,e.createElement)("img",{src:n,alt:o,width:r})," ")}const a=window.wc.wcBlocksRegistry,c=async(e=!1)=>{try{const t=new URLSearchParams;t.append("action","get_payment_methods"),t.append("postfinancecheckout_nonce",window.postfinancecheckout_block_params?.postfinancecheckout_nonce||""),e&&t.append("updateTransaction","1");const n=await fetch(wp.apiFetch.nonceEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t});if(!n.ok)throw new Error(`HTTP error! Status: ${n.status}`);const o=await n.json();if(!o)throw new Error("No payment methods found");return o}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,a.registerPaymentMethod)({name:c.name,label:(0,e.createElement)(r,{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")&&!document.body.classList.contains("woocommerce-order-received")){const e=document.getElementById("postfinancecheckout-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(!0);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),o=t[0];if("string"==typeof o&&o.includes("/wc/store/v1/batch")){const e=t[1]?.body?JSON.parse(t[1].body):null;e&&e.requests&&Array.isArray(e.requests)&&e.requests.some((e=>"/wc/store/v1/cart/update-customer"===e.path))&&function(e){for(const t of e){const e=(t.getAttribute("type")||"").toLowerCase();if("select"!==t.tagName.toLowerCase()){if("checkbox"!==e)if("radio"!==e){if(!t.value.toString().trim())return!1}else{const e=t.getAttribute("name");if(!document.querySelector(`input[type="radio"][name="${e}"]:checked`))return!1}}else if(!t.value)return!1}return!0}((document.querySelector("form.woocommerce-checkout")||document.querySelector("form.checkout")||document).querySelectorAll('[required], [aria-required="true"]'))&&(async()=>{try{const e=await c(),t=(0,a.getPaymentMethods)();e.forEach((e=>{var n;const o={...null!==(n=t[e.name])&&void 0!==n&&n,canMakePayment:()=>e.isActive};(0,a.registerPaymentMethod)(o)}))}catch(e){console.error("Error handling batch response:",e)}})()}return n}}()}})();