1&&void 0!==arguments[1]&&arguments[1];return _.hasOwnProperty(e)?_[e]:t}("currency"),C=h(k);(0,s.createContext)(C);var H=h;addEventListener("DOMContentLoaded",(function(){var e,t=!1,r=0,n=".payment_method_cawl-hosted-tokenization input.woocommerce-SavedPaymentMethods-tokenInput",i=".shop_table.woocommerce-checkout-review-order-table",s="",l=function(){if(s){var e=document.querySelector(i);e&&(e.innerHTML=s)}},f=function(e){var t=document.querySelector(i);if(t){var r=e/WlopHtConfig.currency.centFactor,n=t.querySelector("tfoot");if(n){var o=WlopHtConfig.total/WlopHtConfig.currency.centFactor+r,a=H(WlopHtConfig.currency),c=a.formatAmount(o),u=a.formatAmount(r),s=n.querySelector(".wlop-order-surcharge");if(s){var l=s.querySelector(".woocommerce-Price-amount bdi");l&&(l.textContent=u)}else{(s=document.createElement("tr")).classList.add("wlop-order-surcharge"),s.innerHTML="\n\t\t\t\t| ".concat((0,d.__)("Surcharge","worldline-for-woocommerce"),' | \n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t').concat(u,"\n\t\t\t\t\t\n\t\t\t\t | \n\t\t\t");var f=n.querySelector(".order-total");f?n.insertBefore(s,f):n.appendChild(s)}var p=n.querySelector(".order-total .woocommerce-Price-amount bdi");p&&(p.textContent=c)}}},p=function(){return document.querySelector("#"+WlopHtConfig.wrapper.id)};function m(){var t=p();if(t){e&&e.destroy(),t.innerHTML="";var n={hideCardholderName:!1,hideTokenFields:!1};WlopHtConfig.surcharge&&(n.surchargeCallback=function(e){if(e.surcharge.success){var t=e.surcharge.result.surchargeAmount.amount;Number.isInteger(t)||console.error("Invalid surcharge amount received. "+t),r=t,g(t)}else console.error(e.surcharge.error)}),e=new Tokenizer(WlopHtConfig.url,WlopHtConfig.wrapper.id,n)}}if(p()){var y=function(){var e=p();if(e){var t=c()===WlopHtConfig.gateway.id;u(e,t),t?r>0&&f(r):l()}},h=function(){e&&t&&e.setAmount(WlopHtConfig.total,WlopHtConfig.currency.code)},g=function(e){if(WlopHtConfig.surcharge){var t=document.getElementById(WlopHtConfig.surcharge.wrapper.id);if(t){if(e<=0)return t.innerHTML="",void l();var r=H(WlopHtConfig.currency).formatAmount(e/WlopHtConfig.currency.centFactor);t.innerHTML=(0,d.sprintf)(
/**
* translators: %s the surcharge amount, like $0.23
*/
/**
* translators: %s the surcharge amount, like $0.23
*/
(0,d.__)("Includes surcharge of %s","worldline-for-woocommerce"),r),c()===WlopHtConfig.gateway.id?f(e):l()}}},v=function(){var r=o(a().mark((function r(){var o,i,c;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(o=p()){r.next=3;break}throw new Error("Hosted tokenization iframe wrapper not found.");case 3:if(!(o.childNodes.length>0)){r.next=5;break}return r.abrupt("return");case 5:if(i=o.closest(".wc_payment_methods"),(c=null==i?void 0:i.offsetWidth)&&c>0&&c<450&&o.classList.add("wlop-ht-narrow"),t)try{e.destroy()}catch(e){}return r.next=11,e.initialize();case 11:b(),y(),t=!0,h(),document.querySelectorAll(n).forEach((function(e){e.addEventListener("click",S)})),S();case 18:case"end":return r.stop()}}),r)})));return function(){return r.apply(this,arguments)}}(),w=function(){var e=o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return["wlop_hosted_tokenization_id","wlop_screen_height","wlop_screen_width"].forEach((function(e){var t;null===(t=document.querySelector('[name="'.concat(e,'"]')))||void 0===t||t.remove()})),m(),e.next=4,v();case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),b=function(){var r=document.querySelector("#place_order");if(!r)throw new Error("Place order button not found.");if(!r.dataset.wlopHtHandlerAdded){var n=!1;r.dataset.wlopHtHandlerAdded="true",r.addEventListener("click",function(){var i=o(a().mark((function o(i){var u,s;return a().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(!n){o.next=2;break}return o.abrupt("return");case 2:if(t){o.next=4;break}return o.abrupt("return");case 4:if(c()===WlopHtConfig.gateway.id){o.next=6;break}return o.abrupt("return");case 6:return i.preventDefault(),i.stopImmediatePropagation(),o.next=10,e.submitTokenization();case 10:(u=o.sent).success?(s=u.hostedTokenizationId,r.insertAdjacentHTML("afterend",'')),r.insertAdjacentHTML("afterend",'')),r.insertAdjacentHTML("afterend",'')),n=!0,r.click()):alert(u.error.message);case 12:case"end":return o.stop()}}),o)})));return function(_x){return i.apply(this,arguments)}}())}},S=function(){var t=document.querySelector(n+":checked");if(t){var o=t.value;if("new"===o)r=0,g(0),e.useToken();else{var i=WlopHtConfig.tokens[o];e.useToken(i)}}},_=function(){var e=o(a().mark((function e(){var t,r,n,o=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=o.length>0&&void 0!==o[0]&&o[0],e.next=3,jQuery.ajax({type:"post",dataType:"json",url:WlopHtConfig.ajax,data:{action:"wlop_hosted_tokenization_config",withoutUrl:t}});case 3:r=e.sent,n=r.data,t&&(n.url=WlopHtConfig.url,n.tokens=WlopHtConfig.tokens),WlopHtConfig=n;case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();m(),v(),jQuery(document.body).on("updated_checkout",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0,(t=document.querySelector(i))&&(s=t.innerHTML),e.next=3,_(!0);case 3:return e.next=5,v();case 5:h();case 6:case"end":return e.stop()}var t}),e)})))),jQuery(document.body).on("updated_checkout payment_method_selected",(function(){y()})),jQuery(document.body).on("checkout_error",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c()===WlopHtConfig.gateway.id){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,_();case 4:return e.next=6,w();case 6:case"end":return e.stop()}}),e)}))));var k=document.querySelector("form.checkout");k&&k.querySelectorAll("input").forEach((function(e){e.addEventListener("keydown",(function(e){"Enter"===e.key&&c()===WlopHtConfig.gateway.id&&e.preventDefault()}))})),setTimeout((function(){jQuery(document.body).trigger("wc-credit-card-form-init")}),0)}}))}();