(()=>{"use strict";var e={n:t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},d:(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{BaseController:()=>c,CartController:()=>m,CheckoutController:()=>y,ExpressCheckoutController:()=>P,MiniCartController:()=>b,ProductController:()=>p});const i=window.jQuery;var s=e.n(i);const n=window.wp.apiFetch;var a=e.n(n);const r=window.wcPPCP.utils,o=window.lodash,d=class{constructor(e,t){this.context=e,this.controller=t}populate(e,t={}){(this.context.isCheckout()||this.context.isExpressCheckout())&&this.syncDOMToMap(t),e?.billing&&this.populateBilling(e.billing,t),e?.shipping&&!t.skipShipping&&t.needsShipping&&this.populateShipping(e.shipping,t)}syncDOMToMap(e={}){["first_name","last_name","company","address_1","address_2","city","state","postcode","country","email","phone"].forEach(e=>{const t=s()(`[name="billing_${e}"]`);t.length&&(0,r.setFieldValue)(e,t.val(),"billing")}),e.needsShipping&&["first_name","last_name","company","address_1","address_2","city","state","postcode","country","phone"].forEach(e=>{const t=s()(`[name="shipping_${e}"]`);t.length&&(0,r.setFieldValue)(e,t.val(),"shipping")})}populateBilling(e,t){const{email:i,phone:n,...a}=e;(0,o.isEmpty)(a)||(this.context.isCheckout()||this.context.isExpressCheckout()?(0,r.isValidAddress)(a,["first_name","last_name","phone"])&&!(0,o.isEqual)(this.controller.getCartAddress("billing",!0),(0,o.omit)(a,["first_name","last_name"]))&&(this.controller.update_required=!0,this.populateAddressFields(a,"billing"),s()(document.body).one("updated_checkout",()=>{this.populateAddressFields(a,"billing")})):this.populateAddressFields(a,"billing")),i&&(this.context.isCheckout()&&(0,r.isValid)("billing_email")||(0,r.setFieldValue)("billing_email",i)),n&&((0,r.setFieldValue)("billing_phone",n),t.needsShipping&&(0,r.setFieldValue)("shipping_phone",n))}populateShipping(e,t){const{phone:i,...n}=e;if(!(0,o.isEmpty)(n))if(this.context.isCheckout()||this.context.isExpressCheckout()){const e=this.controller.getCartFullAddress("shipping",!0);(0,o.isEqual)(e,n)||(this.controller.update_required=!0,this.populateAddressFields(n,"shipping"),s()(document.body).one("updated_checkout",()=>{this.populateAddressFields(n,"shipping")})),(0,r.isValidAddress)(this.controller.getCartFullAddress("billing",!0),["phone","email"])||(n.first_name&&n.last_name&&!(0,r.isValid)("billing_first_name")&&!(0,r.isValid)("billing_last_name")&&((0,r.setFieldValue)("first_name",n.first_name,"billing"),(0,r.setFieldValue)("last_name",n.last_name,"billing")),this.populateAddressFields(n,"billing"))}else this.populateAddressFields(n,"shipping"),(0,r.isValidAddress)(this.controller.getCartFullAddress("billing",!0),["phone","email"])||this.populateAddressFields(n,"billing");i&&(0,r.setFieldValue)("shipping_phone",i),(this.context.isCheckout()||this.context.isExpressCheckout())&&this.maybeShipToDifferentAddress()}maybeShipToDifferentAddress(){if(s()('[name="ship_to_different_address"]')?.length){const e=this.controller.getCartFullAddress("billing"),t=this.controller.getCartFullAddress("shipping"),i=!(0,o.isEqual)(e,t);s()('[name="ship_to_different_address"]').prop("checked",i).trigger("change")}}populateAddressFields(e,t){for(let i in e)(0,r.setFieldValue)(i,e[i],t)}},h=window.wcPPCP.actions;var l=e.n(h);class c{static attributionDataStored=!1;constructor({id:e,settings:t,cart:i,context:s,gateway:n,container:a=null,paymentElementSelector:r=null}){this.id=e,this.cart=i,this.gateway=n,this.context=s,this.settings=t,this.container=a||`li.payment_method_${e}`,this.paymentElementSelector=r,this.order_field_key=n.getOrderFieldKey(),this.billing_token_key=n.getTokenFieldKey(),this.isPaymentMethodAvailable=!0,this.fields=new d(this.context,this),this.actions=new(l()),this.gateway.setController(this),this.gateway.initialize()}initialize(){this.loadPayPalScript().then(async()=>{await this.createPaymentElement()})}loadPayPalScript(){return new Promise((e,t)=>{(0,r.loadPayPalSdk)(this.getPayPalSDKArgs()).then(t=>{this.paypal=t,this.gateway.setPayPal(t),e()}).catch(e=>{console.log(e),e?.code&&this.submitError((0,r.getErrorMessage)(e)),t()})})}getPayPalSDKArgs(){return(0,r.getPayPalQueryParams)()}async createPaymentElement(){if(this.configurationError=null,!this.cart.isPaymentMethodAvailable(this.gateway.id))return this.isPaymentMethodAvailable=!1,void this.onPaymentUnavailable();let e=!1;try{e=await this.gateway.canMakePayment()}catch(t){e=!1,t instanceof r.ConfigurationError?this.configurationError=t.message:console.error("Payment method availability check failed:",t)}if(!e)return this.isPaymentMethodAvailable=!1,void this.onPaymentUnavailable();this.isPaymentMethodAvailable=!0;const t=this.getElementContainer();if(t&&this.gateway.shouldCreateElement(t)){if(t instanceof NodeList)for(let e=0;e<t.length;e++){const i=t[e];await this.gateway.createPaymentElement(i)}else await this.gateway.createPaymentElement(t);this.$paymentElement=s()(t),this.onPaymentElementReady()}}getPaymentElement(){return this.$paymentElement}destroyPaymentElement(){this.gateway.destroyPaymentElement?.()}disablePaymentElement(e=!1){this.gateway.disablePaymentElement?.(),e&&this?.$paymentElement&&this.$paymentElement.addClass("disabled")}enablePaymentElement(){this.gateway.enablePaymentElement?.(),this.$paymentElement&&this.$paymentElement.removeClass("disabled")}displayPaymentElement(){this.getPaymentElement()?.show()}hidePaymentElement(){this.getPaymentElement()?.hide()}needsShipping(){return this.cart.needsShipping()}getElementContainer(){return null}onPaymentUnavailable(){this.actions.doAction("payment_unavailable",this)}onPaymentElementReady(){this.actions.doAction("payment_element_ready",this)}onCancel(){this.enablePaymentElement()}onError(e,t){this.currentError?(this.submitError(this.currentError),this.currentError=null):this.submitError(e),this.enablePaymentElement(),s()(document.body).triggerHandler("wc_ppcp_on_error",[this,t,e])}fetchBillingToken(e){return a()({method:"GET",path:`/wc-ppcp/v1/billing-agreement/token/${e}`})}createPaymentToken(e,t={}){return a()({method:"POST",path:"/wc-ppcp/v1/vault/payment-tokens",data:{setup_token:e,...t}})}createOrder(e,t){return this.cart.createOrder({...e,payment_method:this.id}).catch(e=>(this.currentError=e,e))}createVaultSetupToken(e={}){return this.disablePaymentElement(!0),a()({method:"POST",url:(0,r.getRestPath)("/wc-ppcp/v1/vault/setup-tokens"),data:{context:this.context.getPage(),payment_method:this.id,...e}}).then(e=>e.id).catch(e=>{throw this.currentError=e,this.enablePaymentElement(),e})}onShippingChange(e){return this.cart.updateShipping({...e,payment_method:this.id}).then(e=>e).catch(e=>{throw e})}onBillingChange(e){return this.cart.updateBilling({payment_method:this.id,...e}).then(e=>e).catch(e=>{throw e})}submitError(e){}getShippingPrefix(){return"shipping"}getCartAddress(e,t=!1){return{address_1:(0,r.getFieldValue)("address_1",e,t),address_2:(0,r.getFieldValue)("address_2",e,t),state:(0,r.getFieldValue)("state",e,t),city:(0,r.getFieldValue)("city",e,t),postcode:(0,r.getFieldValue)("postcode",e,t),country:(0,r.getFieldValue)("country",e,t)}}getCartFullAddress(e,t=!1){return{first_name:(0,r.getFieldValue)("first_name",e,t),last_name:(0,r.getFieldValue)("last_name",e,t),address_1:(0,r.getFieldValue)("address_1",e,t),address_2:(0,r.getFieldValue)("address_2",e,t),state:(0,r.getFieldValue)("state",e,t),city:(0,r.getFieldValue)("city",e,t),postcode:(0,r.getFieldValue)("postcode",e,t),country:(0,r.getFieldValue)("country",e,t)}}onClick(){this.storeAttributionValues()}async validate(){return!0}populateCheckoutFields(e){let t=this.actions.applyFilters("field_population_options",{skipShipping:!1,needsShipping:this.needsShipping()},this);this.fields.populate(e,t),this.actions.doAction("after_populate_checkout_fields",this)}submit(e=null){return e&&this.populateCheckoutFields(e),this.showProcessing(),a()({method:"POST",url:(0,r.getRestRoute)("cart/checkout"),data:this.getCartCheckoutData()}).then(e=>{if(e.result&&"success"==e.result)window.location=e.redirect;else if(e.messages)return this.submitError(e.messages)}).catch(e=>{e.code&&this.submitError(e.message)})}getCartCheckoutData(){return{payment_method:this.id,context:this.context.getPage(),...(0,r.fieldsToJson)()}}getProcessingSelector(){return"body"}showProcessing(){s()(this.getProcessingSelector())?.block({message:this.getProcessingMessage(),overlayCSS:{background:"#fff",opacity:.6}})}hideProcessing(){s()(this.getProcessingSelector())?.unblock()}getProcessingMessage(){return'<div class="wc-ppcp-loader">\n                        <div></div>\n                        <div></div>\n                        <div></div>\n                      </div>'}getFullName(e){const t=[(0,r.getFieldValue)("first_name",e),(0,r.getFieldValue)("last_name",e)].filter(Boolean);return 0==t.length?null:1==t.length?t[0]:`${t[0]} ${t[1]}`}updateGatewaySettings(e){const t=`${this.id}_data`;e[t]&&(this.gateway.settings={...this.gateway.settings,...e[t]})}isOrderAttributionEnabled(){return"undefined"!=typeof wc_order_attribution&&null!==document.querySelector("wc-order-attribution-inputs")}storeAttributionValues(){if(c.attributionDataStored)return;if(this.context.isCheckout()||!this.isOrderAttributionEnabled())return;const e=wc_order_attribution.params.prefix;s()('input[type="hidden"][name^="'+e+'"]').each((e,t)=>{var i=s()(t),n=i.attr("name");(0,r.setFieldValue)(n,i.val(),null)}),c.attributionDataStored=!0}getLineItems(){return this.cart.getLineItems()}getShippingOptions(){return this.cart.getShippingOptions()}getSelectedShippingMethod(){return this.cart.getSelectedShippingMethod()}getCurrency(){return this.cart.getCurrency()}getTotal(e="string"){return this.cart.getTotal()}getTotalCents(){return this.cart.getTotalCents()}}const u=c;class p extends u{_excludedKeys=["add-to-cart","quantity","variation_id"];constructor(e,t){super(t),this.product=e}initialize(){this.actions.addAction("found_variation",this.onFoundVariation.bind(this)),this.actions.addAction("reset_variation",this.onResetVariation.bind(this)),this.setMaxWidth(),super.initialize()}onPaymentElementReady(){super.onPaymentElementReady(),this.product.isVariableProduct()&&(this.product.isVariationSelected()&&this.product?.variation?.is_in_stock?this.enablePaymentElement():this.disablePaymentElement(!0))}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.payment_method_${this.gateway.id}`).hide()}needsShipping(){return this.cart.isEmpty()?this.product.needsShipping():super.needsShipping()}getElementContainer(){const e=`wc-${this.id}-product-button-container`,t=document.querySelectorAll(`.${e}`);return t&&t.length>0?t:document.getElementById(e)}setMaxWidth(){if("add_to_cart"==this.settings?.product?.button_width){this.buttonWidth=s()("form.cart div.quantity").outerWidth(!0)+s()(".single_add_to_cart_button").outerWidth();var e=s()(".single_add_to_cart_button").css("marginLeft");e&&(this.buttonWidth+=parseInt(e.replace("px",""))),s()(this.container).css("max-width",this.buttonWidth+"px")}}submitError(e){this.hideProcessing(),(0,r.submitErrorMessage)(e,"div.woocommerce-notices-wrapper")}addToCart(){return this.cart.addToCart({payment_method:this.id,product_id:this.product.getId(),variation_id:this.product.getVariationId(),qty:this.product.getQuantity(),variation:this.product.getVariationData(),needs_setup_token:this.settings.needsSetupToken,...(0,r.convertFormToJson)(s()("form.cart"),this._excludedKeys)}).then(e=>{if(!e.code)return this._cartItemKey=e.cart_item_key,e.order_id;this.currentError=e}).catch(e=>(this.currentError=e,this.submitError(e)))}createOrder(){return this.addToCart()}createVaultSetupToken(e={}){return this.addToCart().then(()=>super.createVaultSetupToken(e))}async removeCartItem(){this._cartItemKey&&await this.cart.removeCartItem(this._cartItemKey)}onFoundVariation(e,t){e?(this.destroyPaymentElement(),this.createPaymentElement()):t.variation.is_in_stock?this.enablePaymentElement():this.disablePaymentElement(!0)}onResetVariation(){this.disablePaymentElement(!0)}onCancel(){this.removeCartItem().finally(()=>{super.onCancel()})}getTotal(e){return this.cart.isEmpty()?this.product.getTotal(e):super.getTotal(e)}getTotalCents(){return this.cart.isEmpty()?this.product.getTotalCents():super.getTotalCents()}getLineItems(){return this.cart.isEmpty()?this.product.getLineItems():super.getLineItems()}}class m extends u{initialize(){this.actions.addAction("cart_updated",this.onCartUpdated.bind(this)),s()(window).on("resize",this.doCartHtml.bind(this)),s()(document).on("change",'input[name^="shipping_method"]',this.onShippingSelected.bind(this)),super.initialize(),this.doCartHtml()}getElementContainer(){return document.getElementById(`wc-${this.id}-cart-button-container`)}onCartUpdated(e){super.initialize(),this.doCartHtml()}onShippingSelected(){this.storeAttributionValues()}submitError(e){this.hideProcessing(),(0,r.submitErrorMessage)(e,"div.woocommerce-notices-wrapper","checkout")}doCartHtml(){const e=s()(".checkout-button"),t=e.outerWidth();t&&s()(".wc-ppcp-cart-payments__container").length&&s()(".wc-ppcp-cart-payments__container").width(t),"none"!==e.css("float")&&s()(".wc-ppcp-cart-payments__container ").css("float",e.css("float"))}onPaymentElementReady(){super.onPaymentElementReady(),s()(".wc-ppcp-cart-payments__container").show()}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.payment_method_${this.gateway.id}`).hide()}}const g=window.wcPPCP.paymentMethods;class y extends u{constructor(e){super(e),this.order=e.order,this.shippingAddressChanged=!1,this.promises=[]}initialize(){super.initialize(),this.actions.addAction("updated_checkout",this.updatedCheckout.bind(this)),s()(document.body).on("update_checkout",this.updateCheckout.bind(this)),this.context.isCheckout()?(s()(document.body).on("payment_method_selected",this.paymentMethodSelected.bind(this)),s()("form.checkout").on(`checkout_place_order_${this.id}`,this.onCheckoutPlaceOrder.bind(this))):(s()(document.body).on("change",'input[name="payment_method"]',this.paymentMethodSelected.bind(this)),s()(document.body).on("click","#place_order",this.onClickPlaceOrder.bind(this))),s()(document.body).on("checkout_error",this.onCheckoutError.bind(this)),s()(document.body).on("click",`.wc-${this.gateway.id}-cancel__payment`,this.cancelPayment.bind(this)),s()(document.body).on("change",'[name="terms"]',this.handleTermsClick.bind(this)),s()(document.body).on("change",'[type="checkbox"]',this.handleCheckboxChange.bind(this)),s()(document.body).on("change",`[name="wc-${this.id}-payment-token"]`,this.onPaymentTokenClick.bind(this)),window.addEventListener("hashchange",this.handleHashError.bind(this)),this.handleOrderPay()}async createPaymentElement(){await Promise.all(this.promises),this.promises=[],!this.context.isCheckout()||this.isEnabledForCheckoutSection()?super.createPaymentElement().then(()=>{this.paymentMethodSelected()}):this.hidePaymentMethodRow()}isEnabledForCheckoutSection(){var e;return null===(e=this.gateway.settings?.sections?.includes("checkout"))||void 0===e||e}hidePaymentMethodRow(){this.context.isOrderPay()?s()(`form#order_review li.payment_method_${this.id}`).hide():s()(`form.checkout li.payment_method_${this.id}`).hide()}onPaymentUnavailable(){if(super.onPaymentUnavailable(),!this.configurationError)return void this.hidePaymentMethodRow();const e=(0,r.isAdminUser)()?this.gateway.settings?.i18n?.unavailable_admin||this.configurationError:this.gateway.settings?.i18n?.unavailable||"Payment method unavailable",t=s()(`div.payment_method_${this.id}`).find(`.wc-${this.id}-payment-method__container`);t.find(".woocommerce-info").remove(),t.prepend(`<div class="woocommerce-info"><p>${e}</p></div>`)}needsShipping(){return this.context.isOrderPay()?this.order.needsShipping():!this.context.isAddPaymentMethod()&&this.cart.needsShipping()}getCurrency(){return this.context.isOrderPay()?this.order.getCurrency():super.getCurrency()}getTotal(e="string"){return this.context.isOrderPay()?this.order.getTotal():super.getTotal(e)}getTotalCents(){return this.context.isOrderPay()?this.order.getTotalCents():super.getTotalCents()}getLineItems(){return this.context.isOrderPay()?this.order.getLineItems():super.getLineItems()}updatedCheckout(e){super.initialize(),this.paymentMethodSelected(),(this.isOrderReview()||this.isReadyToCheckout())&&this.displayPaymentReadyMessage()}updateCheckout(){this.promises.push(new Promise(e=>{s()(document.body).one("updated_checkout",()=>{e()})}))}paymentMethodSelected(){if(this.isPaymentGatewaySelected()){if(!this.isPaymentMethodAvailable)return void this.displayPlaceOrderButton();this.gateway.supports("place_order_button")?(this.displayPlaceOrderButton(),this.isReadyToCheckout()&&this.isPaymentSectionPlacement()&&this.hidePaymentElement()):this.isReadyToCheckout()||this.isSavedPaymentMethodSelected()?this.displayPlaceOrderButton():(this.displayPaymentElement(),this.hidePlaceOrderButton())}else if(!this.gateway.supports("place_order_button")){this.hidePaymentElement();const e=s()('[name="payment_method"]:checked')?.val();e&&!(0,g.getPaymentMethod)(e)&&this.displayPlaceOrderButton()}}handleHashError(e){var t=e.newURL.match(/ppcp_error=(.*)/);if(t){const{1:e}=t;"true"==e&&(this.displayPaymentElement(),history.pushState({},"",window.location.pathname+window.location.search))}}isOrderReview(){let e=window?.location?.search?.match(/_ppcp_order_review=(.*)/);return e?.length>0}handleOrderPay(){if(this.isOrderReview())try{let e=window?.location?.search?.match(/_ppcp_order_review=(.*)/);const{1:t}=e,{payment_method:i,paypal_order:n,fields:a}=JSON.parse(atob(decodeURIComponent(t)));if((0,r.setFieldValue)(this.order_field_key,n,""),!(0,o.isEmpty)(a))for(let e in a)(0,r.setFieldValue)(e,a[e],"");if(this.hidePaymentElement(),this.needsShipping()&&s()('[name="ship_to_different_address"]')?.length){const e=!(0,o.isEqual)(this.getCartAddress("billing"),this.getCartAddress("shipping"));s()('[name="ship_to_different_address"]').prop("checked",e).trigger("change")}}catch(e){console.log(e)}}createOrder(e,t){if(this.context.isOrderPay())return this.order.createOrder(this.id);{const e={...this.convertFormToData(),context:this.context.getPage(),payment_method:this.id};return this.cart.createOrder(e)}}createVaultSetupToken(e={}){return this.context.isOrderPay()||(e={...this.convertFormToData(),context:this.context.getPage(),payment_method:this.id}),super.createVaultSetupToken(e)}displayPlaceOrderButton(){this.getPlaceOrderButton()?.removeClass("wc-ppcp-hide-button")}hidePlaceOrderButton(){this.getPlaceOrderButton()?.addClass("wc-ppcp-hide-button")}getPlaceOrderButton(){let e=s()("#place_order");return e.length||(e=s()('[name="woocommerce_checkout_place_order"]')),e.length||(e=s()('form.checkout button[type="submit"]')),e.length||(e=s()('form[id="order_review"] button[type="submit"]')),e}getButtonPlacement(){return this.settings?.buttonPlacement||"place_order"}isPlaceOrderPlacement(){return"place_order"===this.getButtonPlacement()}isPaymentSectionPlacement(){return"payment_method"===this.getButtonPlacement()}getElementContainer(){if(this.paymentElementSelector)return document.querySelector(this.paymentElementSelector);const e=this.getButtonPlacement(),t=`wc-${this.id}-checkout-container`,i=`.${t}`,n="place_order"===e&&!this.gateway.supports("place_order_button");return document.querySelector(i)||(n?this.getPlaceOrderButton().after(`<div class="${t}"></div>`):"payment_method"===e&&s()(`div.payment_method_${this.id}`).find(`.wc-${this.id}-payment-method__container`).append(`<div class="${t}"></div>`)),n&&s()(i).hide(),document.querySelector(i)}isPaymentGatewaySelected(){return s()('[name="payment_method"]:checked')?.val()===this.id}submitError(e){return"validation_errors"===e?.code?(this.getForm().find(".input-text, select, input:checkbox").trigger("validate").trigger("blur"),(0,r.submitErrorMessage)(e.data.messages,this.getForm(),"checkout")):(0,r.submitErrorMessage)(e,this.getForm(),"checkout")}getShippingPrefix(){return s()('[name="ship_to_different_address"]')?.length&&s()('[name="ship_to_different_address"]').is(":checked")?"shipping":"billing"}isCheckoutReviewRequired(e){return!(!this.needsShipping()||!this.actions.applyFilters("is_checkout_review_required",!this.shippingAddressChanged,this)||(0,o.isEmpty)(e.shipping_address)||(0,o.isEqual)({city:e.shipping_address.city,state:e.shipping_address.state,postal_code:e.shipping_address.postal_code,country_code:e.shipping_address.country_code},{city:(0,r.getFieldValue)("shipping_city"),state:(0,r.getFieldValue)("shipping_state"),postal_code:(0,r.getFieldValue)("shipping_postcode"),country_code:(0,r.getFieldValue)("shipping_country")}))}getForm(){return this.context.isCheckout()||this.context.isExpressCheckout()?s()(this.container).closest("form.checkout"):s()(this.container).closest("form")}validateTerms(){return!s()('[name="terms"]').filter(":visible").length||s()('[name="terms"]').is(":checked")}onClickPlaceOrder(e){this.isPaymentGatewaySelected()&&(this.onCheckoutPlaceOrder(e,null)||e.preventDefault())}onCheckoutPlaceOrder(e,t=null){if(this.isSavedPaymentMethodSelected())return!0;if(this.isReadyToCheckout()||this.gateway.isPaymentReady?.())return!0;if(!this.validateSync())return!1;if(this.gateway.supports("place_order_button")&&this.isPaymentSectionPlacement()&&!this.isReadyToCheckout())return this.submitError((0,r.getErrorMessage)({code:"order_button_click"}).replace("%s",this.gateway.settings.title)),!1;try{this.gateway.validatePaymentElement()}catch(e){return this.submitError(e),!1}return!this.gateway.supports("create_payment_method")||(this.gateway.createPaymentMethod(t).catch(e=>{this.submitError(e)}),!1)}isTermsVisible(){return s()('[name="terms"]').filter(":visible").length>0}handleTermsClick(){this.isPlaceOrderPlacement()&&this.gateway.supports("disable_for_terms")&&s()('[name="terms"]').filter(":visible").length&&(s()('[name="terms"]').is(":checked")?this.enablePaymentElement():this.disablePaymentElement())}handleCheckboxChange(){setTimeout(()=>{this.isTermsVisible()&&this.handleTermsClick()},250)}onPaymentTokenClick(e){this.isSavedPaymentMethodSelected()?(this.hidePaymentElement(),this.displayPlaceOrderButton()):(this.displayPaymentElement(),this.gateway.supports("place_order_button")||this.hidePlaceOrderButton())}validateSync(){return!(this.isPlaceOrderPlacement()&&!this.validateTerms()&&(this.submitError({code:"terms"}),1))}async validate(){if(!this.validateSync())return!1;if(this.context.isCheckout())try{this.gateway.supports("api_form_validation")&&await this.apiFormValidation(),this.gateway.supports("form_validation")&&(this.isCheckoutFormValid()||(this.disablePaymentElement(!0),await this.apiFormValidation().finally(()=>{this.enablePaymentElement()})))}catch(e){return this.submitError(e),!1}return!0}onShippingChange(e){if(e?.shipping_method){let t=(0,r.extractShippingMethod)(e.shipping_method);for(let e of Object.keys(t)){const i=t[e],n=s()(`[name="shipping_method[${e}]"][value="${i}"]`);n.length?n.prop("checked",!0):this.update_required=!0}}return e.address&&(this.shippingAddressChanged=!(0,o.isEqual)(e.address,{city:(0,r.getFieldValue)("shipping_city"),state:(0,r.getFieldValue)("shipping_state"),postcode:(0,r.getFieldValue)("shipping_postcode"),country:(0,r.getFieldValue)("shipping_country")})),e={...this.convertFormToData(),...e},this.actions.doAction("checkout_on_shipping_change",e,this),super.onShippingChange(e)}displayPaymentReadyMessage(){s()(`.wc-${this.gateway.id}-popup__container`).hide(),s()(`.wc-${this.gateway.id}-order-review-message__container`).show();const e=s()(`.wc-${this.gateway.id}-order-review__message`).text().replace("%s",s()("#place_order").text());s()(`.wc-${this.gateway.id}-order-review__message`).text(e)}hidePaymentReadyMessage(){s()(`.wc-${this.gateway.id}-popup__container`).show(),s()(`.wc-${this.gateway.id}-order-review-message__container`).hide()}cancelPayment(e){e.preventDefault(),(0,r.setFieldValue)(this.order_field_key,"",""),(0,r.setFieldValue)(`${this.gateway.id}_payment_token`,null,null),this.hidePaymentReadyMessage(),this.displayPaymentElement(),this.gateway.supports("place_order_button")||this.hidePlaceOrderButton()}getProcessingSelector(){return this.container}getProcessingMessage(){return null}fetchBillingToken(e){return this.showProcessing(),super.fetchBillingToken(e).then(e=>(this.hideProcessing(),e))}isReadyToCheckout(){return!(!(0,r.getFieldValue)(this.order_field_key,null)&&!(0,r.getFieldValue)(`${this.gateway.id}_payment_token`,null))}convertFormToData(){return(0,r.convertFormToJson)(s()("form.checkout"))}submit(e=null){e&&this.populateCheckoutFields(e),this.gateway.supports("create_payment_method")||(this.hidePaymentElement(),this.displayPlaceOrderButton()),this.update_required?this.triggerCheckoutUpdate(e):(this.isPaymentSectionPlacement()&&!this.context.isExpressCheckout()||this.submitForm(e),this.isPaymentSectionPlacement()&&this.displayPaymentReadyMessage())}triggerCheckoutUpdate(e){return new Promise(t=>{s()(document.body).one("updated_checkout",()=>{e?.vaultSetupToken&&this.needsShipping()?this.displayPaymentReadyMessage():this.submitForm(e),t()}),s()('[name="billing_country"],[name="billing_state"]').trigger("change"),this.shipToDifferentAddressChecked()&&s()('[name="shipping_country"],[name="shipping_state"]').trigger("change"),s()(document.body).trigger("update_checkout",{update_shipping_method:!1})})}submitForm(e){this.actions.applyFilters("checkout_submit_form",!0,e,this)&&this.getForm().submit()}shipToDifferentAddressChecked(){return!!s()('[name="ship_to_different_address"]')?.length&&s()('[name="ship_to_different_address"]').is(":checked")}getPaymentType(){return"checkout"}isValidationEnabled(){return this.settings.checkoutValidationEnabled}isSavedPaymentMethodSelected(){const e=`[name="wc-${this.id}-payment-token"]:checked`;return this.isPaymentGatewaySelected()&&s()(e).length>0&&"new"!==s()(e).val()}apiFormValidation(){const e={...this.convertFormToData(),context:this.context.getPage(),payment_method:this.id};return a()({method:"POST",url:(0,r.getRestRoute)("checkout/validation"),data:e}).catch(e=>{throw e})}onCheckoutError(){this.isPaymentGatewaySelected()&&(this.enablePlaceOrderButton(),this.isReadyToCheckout()&&this.displayPaymentReadyMessage(),this.actions.doAction(`checkout_error_${this.gateway.id}`,this))}enablePlaceOrderButton(){this.getPlaceOrderButton().prop("disabled",!1)}isCheckoutFormValid(){const e=[];return s()(".validate-required:visible").each((t,i)=>{const n=s()(i).find("input, select, textarea").first();if(n.length&&n.is(":visible")){const t=n.attr("name");"checkbox"===n.attr("type")?n.is(":checked")||e.push(t):""!==n.val()&&null!==n.val()||e.push(t)}}),0===e.length}}const _=y;class P extends _{initialize(){this.actions.addAction("updated_checkout",this.updatedCheckout.bind(this)),this.loadPayPalScript().then(async()=>{this.createPaymentElement()})}updatedCheckout(e){this.paypal&&this.createPaymentElement(),this.updateGatewaySettings(e)}needsShipping(){return this.cart.needsShipping()}validate(){return!0}submit(e=null){super.submit(e);const t=super.getElementContainer();t&&s()(t).hide()}getElementContainer(){if(this.settings?.expressElement){const e=document.querySelector(this.settings.expressElement);if(e)return e}return document.getElementById(`wc-${this.id}-express-button`)}onPaymentElementReady(){this.actions.doAction("payment_element_ready",this);const e=this.getElementContainer();e&&(s()(e).show(),this.addExpressClasses(s()(e))),s()(".wc-ppcp-express-checkout").show()}addExpressClasses(e){if(e.length&&this.gateway.buttons){const t=Object.keys(this.gateway.buttons).length;e.addClass(`button-count_${t}`)}}onClick(){s()('[name="terms"]').prop("checked",!0).trigger("change"),s()(`[name="payment_method"][value="${this.id}"]`).prop("checked",!0).trigger("click"),s()(`[name="wc-${this.id}-payment-token"][value="new"]`).trigger("click")}paymentMethodSelected(){}hidePaymentElement(){}}class b extends u{initialize(){this.actions.addAction("fragments_changed",this.onFragmentsChanged.bind(this)),this.actions.addAction("mini_cart_ready",this.onMiniCartReady.bind(this)),this.actions.addAction("mini_cart_updated",this.onMiniCartReady.bind(this)),super.initialize()}onFragmentsChanged(){this.cart.isEmpty()||super.initialize()}onMiniCartReady(){super.initialize()}onPaymentElementReady(){super.onPaymentElementReady(),s()(this.getElementContainer()).show()}getElementContainer(){const e=document.querySelectorAll(`.wc-ppcp-minicart-${this.id}`);return e&&e.length>0?e:(s()(".woocommerce-mini-cart__buttons").append(`<a id="wc-ppcp-minicart-${this.id}"></a>`),document.getElementById(`wc-ppcp-minicart-${this.id}`))}}(this.wcPPCP=this.wcPPCP||{}).controllers=t})();