(()=>{"use strict";var t={n:e=>{var i=e&&e.__esModule?()=>e.default:()=>e;return t.d(i,{a:i}),i},d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Product:()=>h,default:()=>y});const i=window.jQuery;var n=t.n(i);const a=window.wcPPCP.utils,r=window.lodash,o=window.wcPPCP.actions;var u=t.n(o);function s(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function c(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?s(Object(i),!0).forEach((function(e){l(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function l(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function v(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var h=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d(this,t),this.actions=new(u()),this.data=this.default_data=e,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))}var e,i;return e=t,i=[{key:"needsShipping",value:function(){var t;return this.actions.applyFilters("product_needs_shipping",null===(t=this.data)||void 0===t?void 0:t.needsShipping)}},{key:"getLineItems",value:function(){return this.data.lineItems||[]}},{key:"isVariationSelected",value:function(){return!!this.variation}},{key:"onQuantityChange",value:function(t){var e=this;null!=t&&t.isTrigger?setTimeout((function(){e.actions.doAction("quantity_change",e.getQuantity(),e)}),50):this.actions.doAction("quantity_change",this.getQuantity(),this)}},{key:"foundVariation",value:function(t,e){this.variation=e;var i=c({},this.data);this.data=c(c({},this.data),{price:e.display_price,needsShipping:!e.is_virtual}),this.actions.doAction("found_variation",!(0,r.isEqual)(this.data,i),this)}},{key:"resetVariationData",value:function(){this.variation=null,this.data=this.default_data,this.actions.doAction("reset_variation",this)}},{key:"getQuantity",value:function(){return parseInt(n()('[name="quantity"]').val())||0}},{key:"getPrice",value:function(){var t;return this.actions.applyFilters("product_price",null===(t=this.data)||void 0===t?void 0:t.price,this)}},{key:"getTotal",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"string",e=this.getQuantity()*this.getPrice();return"string"===t&&(e=e.toString()),this.actions.applyFilters("product_total",e,this)}},{key:"getTotalCents",value:function(){var t;return this.actions.applyFilters("product_total_cents",parseInt((null===(t=this.data)||void 0===t?void 0:t.totalCents)||0),this)}},{key:"isVariableProduct",value:function(){return n()('[name="variation_id"]').length>0}},{key:"isVariableProductSelected",value:function(){var t=n()('input[name="variation_id"]').val();return!!t&&"0"!==t}},{key:"getVariationData",value:function(){if(this.isVariableProduct()){var t=this.variation?this.variation.attributes:{},e=document.querySelectorAll('.variations [name^="attribute_"]');return e&&e.forEach((function(e){e.name in t&&""!==t[e.name]||(t[e.name]=e.value||"")})),t}return null}},{key:"getId",value:function(){var t;return parseInt(null===(t=this.data)||void 0===t?void 0:t.id)}},{key:"getVariationId",value:function(){return this.variation?this.variation.variation_id:n()('[name="variation_id"]').val()}}],i&&v(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();const y=new h((0,a.getSetting)("product"));(this.wcPPCP=this.wcPPCP||{}).product=e})();
//# sourceMappingURL=product.js.map