(()=>{"use strict";const e=window.wp.element,t=window?.wc?.wcSettings?.getSetting("acceptblue-google-pay_data",{}),n=window?.wp?.htmlEntities?.decodeEntities(t.title)||window?.wp?.i18n.__("Accept.blue Google Pay","acceptblue-google-pay"),o=n=>{let[o,a]=(0,e.useState)(null),[c,r]=(0,e.useState)(!1),s=(0,e.useRef)(null);const[i,l]=(0,e.useState)([]),[u,p]=(0,e.useState)([]),{eventRegistration:m,emitResponse:d}=n,{onPaymentSetup:f}=m;(0,e.useEffect)((()=>{const e=f((async function(){const e=o;return c?{type:d.responseTypes.ERROR,message:""}:{type:d.responseTypes.SUCCESS,meta:{paymentMethodData:{ab_token:e}}}}));return()=>e()}),[d.responseTypes.ERROR,d.responseTypes.SUCCESS,f,o]);const w={apiVersion:2,apiVersionMinor:0},y={type:"PAYMENT_GATEWAY",parameters:{gateway:"acceptblue",gatewayMerchantId:t.merchant_id}},g={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}},h=Object.assign({},g,{tokenizationSpecification:y});let E=null;function S(){const e=Object.assign({},w);return e.allowedPaymentMethods=[h],e.transactionInfo={...t.transaction_info,totalPrice:(parseFloat(t.transaction_info.totalPrice)+parseFloat(t.surcharge_amount)).toFixed(2).toString()},e.merchantInfo={merchantId:t.merchant_id,merchantName:t.merchant_name},e.callbackIntents=["PAYMENT_AUTHORIZATION"],e}function P(){return null===E&&(E=new google.payments.api.PaymentsClient({environment:t.mode,paymentDataCallbacks:{onPaymentAuthorized:A}})),E}function C(){const e=S();e.transactionInfo={...t.transaction_info,totalPrice:(parseFloat(t.transaction_info.totalPrice)+parseFloat(t.surcharge_amount)).toFixed(2).toString()},P().loadPaymentData(e)}function A(e){return new Promise((function(t,n){(function(e){return new Promise((async function(t,n){const o=e.paymentMethodData.tokenizationData.token;a(o);const c=document.querySelector("form.wc-block-components-form.wc-block-checkout__form button.wc-block-components-checkout-place-order-button");c?(setTimeout((()=>{c.click()}),0),t()):(n(),alert("Error! Something went wrong!"))}))})(e).then((function(){t({transactionState:"SUCCESS"})})).catch((function(){t({transactionState:"ERROR",error:{intent:"PAYMENT_AUTHORIZATION",message:"Insufficient funds",reason:"PAYMENT_DATA_INVALID"}})}))}))}return(0,e.useEffect)((()=>(P().isReadyToPay(Object.assign({},w,{allowedPaymentMethods:[g]})).then((function(e){e.result&&(function(){const e=P().createButton({onClick:C,allowedPaymentMethods:[g]});s.current.innerHTML="",s.current.appendChild(e)}(),function(){const e=S();e.transactionInfo={totalPriceStatus:"NOT_CURRENTLY_KNOWN",currencyCode:"USD"};P().prefetchPaymentData(e)}())})).catch((function(e){console.log(e)})),()=>!1)),[]),(0,e.useEffect)((()=>{window.dispatchEvent(new CustomEvent("pgabfw-renderFooterComponentsGooglePay",{detail:{setComponent:e=>l([...i,e])}})),window.dispatchEvent(new CustomEvent("pgabfw-renderHeaderComponentsGooglePay",{detail:{setComponent:e=>p([...u,e])}}))}),[]),(0,e.createElement)(e.Fragment,null,u.map((e=>e)),(0,e.createElement)("div",{className:"acceptblue-google-pay",ref:s}),i.map((e=>e)))},a={name:"acceptblue-google-pay",label:n,content:(0,e.createElement)(o,null),edit:(0,e.createElement)(o,null),canMakePayment:()=>!0,ariaLabel:n,supports:{features:t.supports}};window.wc.wcBlocksRegistry.registerPaymentMethod(a)})();