function initSumUpGateway(){const e={checkoutId:sumup_gateway_params.checkoutId,onResponse:onSumupResponse,showZipCode:"true"===sumup_gateway_params.showZipCode,locale:sumup_gateway_params.locale,showFooter:!1,showInstallments:"true"===sumup_gateway_params.showInstallments,maxInstallments:sumup_gateway_params.maxInstallments,onPaymentMethodsLoad:sumUpFilterPaymentMethods,onLoad:sumUpOnLoad};sumup_gateway_params.country&&(e.country=sumup_gateway_params.country),SumUpCard.mount(e);const t=document.getElementById("wc-sumup-payment-modal");if(!0!==t.dataset.sumupListener){t.addEventListener("click",function(){t.classList.contains("no-modal")||(t.classList.toggle("disabled"),t.dataset.sumupListener=!0)});let e=document.getElementById("sumup-card");e&&!0!==e.dataset.sumupListener&&e.addEventListener("click",function(t){t.stopPropagation(),e.dataset.sumupListener=!0});let a=document.getElementById("wc-sumup-payment-modal-close");a&&!0!==a.dataset.sumupListener&&a.addEventListener("click",function(e){a.dataset.sumupListener=!0,t.classList.toggle("disabled")})}}function onSumupResponse(e,t){switch(e){case"sent":break;case"invalid":console.error("Error: ",t);break;case"auth-screen":break;case"error":console.error("Error",t),displayError(t.message||sumup_gateway_params.errors.general_error);break;case"success":if("FAILED"===t.status){displayError(t.message||sumup_gateway_params.errors.general_error);break}"PENDING"===t.status&&("boleto"===sumup_gateway_params.paymentMethod&&(setTimeout(function(){const e=document.querySelector('form[data-testid="boleto-download"]'),t=document.querySelector('div[data-testid="pending_screen_content_to_copy"] h4');e&&t&&(sumup_gateway_params.boletoDownloadLink=e.action,sumup_gateway_params.boletoCodeToPay=t.innerText)},50),setTimeout(function(){onSubmitSumup()},100)),"pix"!==sumup_gateway_params.paymentMethod&&"qr_code_pix"!==sumup_gateway_params.paymentMethod||(setTimeout(function(){const e=document.querySelector('textarea[data-testid="pending_screen_content_to_reveal_value"]'),t=document.querySelector('div[data-testid="scannable-barcode"] > img');e&&(sumup_gateway_params.pixCode=e.value,sumup_gateway_params.qrCodeImage=t.src)},50),setTimeout(function(){onSubmitSumup()},100))),"PAID"===t.status&&onSubmitSumup()}}function addMessageToPendingScreenBoleto(e){const t=document.querySelector('div[data-testid="pending-screen"]');if(t){let a=document.createElement("div");a.classList.add("sumup-boleto-pending-screen"),a.innerText=e,t.append(a)}}function sumUpFilterPaymentMethods(e){if(("yes"!==sumup_gateway_params.enablePix||"BR"!==sumup_gateway_params.country)&&e.eligible&&e.eligible.length>0){const t=[];return e.eligible.forEach(e=>{"pix"!==e.id&&"qr_code_pix"!==e.id&&t.push(e.id)}),t}}function sumUpOnLoad(){const e=document.querySelector("#sumup-card form");e&&!0!==e.dataset.sumupListener&&(e.dataset.sumupListener=!0,e.addEventListener("submit",function(t){let a=e.querySelector('input[name="payment_type"]');a&&(sumup_gateway_params.paymentMethod=a.value)})),window.dispatchEvent(new Event("woo_sumup_loaded"))}function onSubmitSumup(){const e=sumup_gateway_params.redirectUrl;if(null!==e.match(/^(https|http):\/\//)){const t=[];"boleto"===sumup_gateway_params.paymentMethod&&(t.push("boleto-code="+encodeURIComponent(sumup_gateway_params.boletoCodeToPay)),t.push("boleto-link="+encodeURIComponent(sumup_gateway_params.boletoDownloadLink))),"pix"!==sumup_gateway_params.paymentMethod&&"qr_code_pix"!==sumup_gateway_params.paymentMethod||(t.push("pix-code="+encodeURIComponent(sumup_gateway_params.pixCode)),t.push("pix-image="+sumup_gateway_params.qrCodeImage)),window.location=t.length>0?e+"&"+t.join("&"):e}}function showSumupPayment(){if(!isSumUpGatewaySelected())return!0;if("paid"===sumup_gateway_params.status)return!0;const e=document.getElementById("wc-sumup-payment-modal");return e&&e.classList.remove("disabled"),!1}function displayError(e){const t=document.querySelector("form.checkout"),a=document.querySelector(".woocommerce-NoticeGroup.woocommerce-NoticeGroup-checkout.woocommerce-error");a&&a.remove();let o=document.createElement("div");o.classList.add("woocommerce-NoticeGroup","woocommerce-NoticeGroup-checkout","woocommerce-error"),o.innerText=e,t.prepend(o),window.scrollTo({top:0,behavior:"smooth"})}function isSumUpGatewaySelected(){const e=document.getElementById("payment_method_sumup");if(e)return e.checked}jQuery(function(e){e(document.body).on("sumupCardInit",initSumUpGateway),e("form#order_review #place_order").on("click",showSumupPayment)});