(()=>{"use strict";var t={n:i=>{var a=i&&i.__esModule?()=>i.default:()=>i;return t.d(a,{a}),a},d:(i,a)=>{for(var n in a)t.o(a,n)&&!t.o(i,n)&&Object.defineProperty(i,n,{enumerable:!0,get:a[n]})},o:(t,i)=>Object.prototype.hasOwnProperty.call(t,i),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},i={};t.r(i),t.d(i,{Product:()=>d,default:()=>u});const a=window.jQuery;var n=t.n(a);const e=window.wcPPCP.utils,r=window.lodash,s=window.wcPPCP.actions;var o=t.n(s);class d{constructor(t={}){this.actions=new(o()),this.data=this.default_data=t,this.variation=!1,n()(document.body).on("change",'[name="quantity"]',this.onQuantityChange.bind(this)),n()(document.body).on("found_variation",this.foundVariation.bind(this)),n()(document.body).on("reset_data",this.resetVariationData.bind(this))}needsShipping(){return this.actions.applyFilters("product_needs_shipping",this.data?.needsShipping)}getLineItems(){return this.data.lineItems||[]}isVariationSelected(){return!!this.variation}onQuantityChange(t){t?.isTrigger?setTimeout(()=>{this.actions.doAction("quantity_change",this.getQuantity(),this)},50):this.actions.doAction("quantity_change",this.getQuantity(),this)}foundVariation(t,i){this.variation=i;const a={...this.data};this.data={...this.data,price:i.display_price,needsShipping:!i.is_virtual},this.actions.doAction("found_variation",!(0,r.isEqual)(this.data,a),this)}resetVariationData(){this.variation=null,this.data=this.default_data,this.actions.doAction("reset_variation",this)}getQuantity(){return parseInt(n()('[name="quantity"]').val())||0}getPrice(){return this.actions.applyFilters("product_price",this.data?.price,this)}getTotal(t="string"){let i=this.getQuantity()*this.getPrice();return"string"===t&&(i=i.toString()),this.actions.applyFilters("product_total",i,this)}getTotalCents(){return this.actions.applyFilters("product_total_cents",parseInt(this.data?.totalCents||0),this)}isVariableProduct(){return n()('[name="variation_id"]').length>0}isVariableProductSelected(){const t=n()('input[name="variation_id"]').val();return!!t&&"0"!==t}getVariationData(){if(this.isVariableProduct()){const t=this.variation?this.variation.attributes:{},i=document.querySelectorAll('.variations [name^="attribute_"]');return i&&i.forEach(i=>{i.name in t&&""!==t[i.name]||(t[i.name]=i.value||"")}),t}return null}getId(){return parseInt(this.data?.id)}getVariationId(){return this.variation?this.variation.variation_id:n()('[name="variation_id"]').val()}}const u=new d((0,e.getSetting)("product"));(this.wcPPCP=this.wcPPCP||{}).product=i})();
//# sourceMappingURL=product.js.map