(()=>{"use strict";var t={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a}),a},d:(e,a)=>{for(var s in a)t.o(a,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:a[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wcPPCP.cart;var a=t.n(e);const s=window.wcPPCP.product;var i=t.n(s);const r=window.wcPPCP.actions;var c=t.n(r);const n=window.wcPPCP.utils,o=window.jQuery;var p=t.n(o);const d=window.wp.hooks,u=class{constructor(t){this.context=t.context,this.actions=t.actions,this.queryParams=t.queryParams,d.defaultHooks.addAction("paypalInstanceCreated","wcPPCP",this.paypalInstanceCreated.bind(this))}paypalInstanceCreated(t,e){this.paypal!==t&&(this.paypal=t,this.queryParams=e,this.createMessage())}isCheckoutFlow(){return"true"!==this.queryParams?.vault}initialize(){(0,n.loadPayPalSdk)(this.queryParams).then(t=>{this.paypal=t,this.createMessage()})}createMessage(){if(!this.paypal)return;const t=this.getMessageContainer();if(t)if(this.isCheckoutFlow()&&this.isActive()){this.showContainer(t);const e={amount:this.getTotal(),currency:this.getCurrency(),placement:this.getPlacement(),style:this.getStyleOptions(this.context),onRender:()=>{this.onRender(t)}};this.paypal.Messages(e).render(t)}else this.hideMessage(t)}showContainer(t){p()(t).closest(".wc-ppcp-paylater-msg__container").show()}hideMessage(t){p()(t).closest(".wc-ppcp-paylater-msg__container").hide()}getMessageContainer(){}getStyleOptions(t){return(0,n.getSetting)("payLaterMessage")?.[t]?.style}getSetting(t){return(0,n.getSetting)("payLaterMessage")?.[t]}getTotal(){return 0}getPlacement(){return""}getCurrency(){return this.queryParams?.currency}isActive(){return(0,n.getSetting)("payLaterMessage").enabled}onRender(t){const e=()=>{const e=t.querySelector('[name^="__zoid__paypal_message"]');e&&(e.style.width="100%",e.style.opacity="1")};e(),setTimeout(e,1e3)}};const h=(0,n.getPayPalQueryParams)(),l=new(c()),g=(0,n.getSetting)("payLaterMessage"),{enabled:m=!1,miniCartEnabled:y=!1}=g,w={actions:l,queryParams:h};m&&((0,n.isProduct)()&&new class extends u{constructor(t){super(t),this.product=t.product}initialize(){this.actions.addAction("quantity_change",this.onQuantityChange.bind(this)),this.actions.addAction("found_variation",this.onFoundVariation.bind(this)),this.actions.addAction("reset_variation",this.onResetVariation.bind(this)),super.initialize()}onQuantityChange(t){this.createMessage()}onFoundVariation(t){this.createMessage()}onResetVariation(t){this.createMessage()}getMessageContainer(){return document.getElementById("wc-ppcp-paylater-msg-product")||p()("form.checkout .shop_table").after('<div id="wc-ppcp-paylater-msg-product"></div>'),document.getElementById("wc-ppcp-paylater-msg-product")}getTotal(){return this.product.getTotal()}getPlacement(){return"product"}}({product:i(),context:"product",...w}).initialize(),(0,n.isCart)()&&new class extends u{constructor(t){super(t),this.cart=t.cart}initialize(){this.actions.addAction("cart_updated",this.refreshMessage.bind(this)),super.initialize()}async refreshMessage(){super.initialize()}getTotal(){return this.cart.getTotal()}getMessageContainer(){const t=this.getSetting("cartLocation");let e=document.getElementById("wc-ppcp-paylater-msg-cart");if(e&&this.getSetting("isShortcode"))return e;switch(t){case"shop_table":e=document.getElementById("wc-ppcp-paylater-msg-cart");break;case"above_button":e=document.getElementById("wc-ppcp-cart-button-container"),e&&(p()(e).find("#wc-ppcp-paylater-msg-cart")?.length||p()(e).prepend('<div id="wc-ppcp-paylater-msg-cart"></div>'),e=document.getElementById("wc-ppcp-paylater-msg-cart"))}return e}getPlacement(){return"cart"}}({cart:a(),context:"cart",...w}).initialize(),(0,n.isCheckout)()&&new class extends u{constructor(t){super(t),this.cart=t.cart,this.promises=[]}initialize(){this.actions.addAction("updated_checkout",super.initialize.bind(this),20),p()(document.body).on("update_checkout",this.updateCheckout.bind(this)),super.initialize()}updateCheckout(){this.promises.push(new Promise(t=>{p()(document.body).one("updated_checkout",()=>{t()})}))}async createMessage(){await Promise.all(this.promises),this.promises=[],super.createMessage()}getMessageContainer(){let t;switch(this.getSetting("checkoutLocation")){case"shop_table":t=document.getElementById("wc-ppcp-paylater-msg-checkout");break;case"above_button":t=document.querySelector(".wc-ppcp-checkout-container"),t?(p()(t).find("#wc-ppcp-paylater-msg-checkout").remove(),p()(t).prepend('<div id="wc-ppcp-paylater-msg-checkout"></div>'),t=document.getElementById("wc-ppcp-paylater-msg-checkout")):setTimeout(this.createMessage.bind(this),500)}return t}getPlacement(){return"payment"}getTotal(){return this.cart.getTotal()}}({cart:a(),context:"checkout",...w}).initialize(),(0,n.isShop)()&&new class extends u{constructor(t){super(t),this.data=t.data}getValidProductTypes(){return this.data.shop.product_types}isSupportedProduct(t){return this.getValidProductTypes().includes(t)}createMessage(){for(const t of this.data.shop.products)this.isSupportedProduct(t.product_type)&&(this.currentProduct=t,super.createMessage())}getMessageContainer(){return document.getElementById(`wc-ppcp-paylater-msg-${this.currentProduct.id}`)||(this.isBelowPrice()?p()(`.post-${this.currentProduct.id} .price`).after(`<div class="wc-ppcp-paylater-msg-shop-container" id="wc-ppcp-paylater-msg-${this.currentProduct.id}"></div>`):p()(`.post-${this.currentProduct.id} a.button`).after(`<div class="wc-ppcp-paylater-msg-shop-container" id="wc-ppcp-paylater-msg-${this.currentProduct.id}"></div>`)),document.getElementById(`wc-ppcp-paylater-msg-${this.currentProduct.id}`)}getTotal(){return this.currentProduct.total}getPlacement(){return"category"}isBelowPrice(){return"below_price"===this.data.shop.msgLocation}showContainer(t){p()(t).show()}hideMessage(t){p()(t).hide()}}({context:"shop",data:g,...w}).initialize()),(y||document.querySelector(".woocommerce-mini-cart__total"))&&new class extends u{constructor(t){super(t),this.cart=t.cart}initialize(){this.actions.addAction("fragments_changed",this.createMessage.bind(this)),super.initialize()}getMessageContainer(){let t=null;switch(p()("#wc-ppcp-minicart-msg").remove(),this.getSetting("miniCartLocation")){case"cart_total":t=document.querySelector(".woocommerce-mini-cart__total"),p()(t).after('<p class="wc-ppcp-minicart-msg__container"><span id="wc-ppcp-minicart-msg"></span></p>');break;case"checkout":t=document.querySelector(".woocommerce-mini-cart__buttons .checkout"),p()(t).after('<span id="wc-ppcp-minicart-msg"></span>')}return t?document.getElementById("wc-ppcp-minicart-msg"):document.querySelector(".woocommerce-mini-cart__total")}showContainer(t){p()(t).show()}hideMessage(t){p()(t).hide()}getTotal(){return this.cart.getTotal()}getPlacement(){return"cart"}}({cart:a(),context:"minicart",...w}).initialize(),(this.wcPPCP=this.wcPPCP||{}).paylaterMessages={}})();