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BAAyB5B,OAAS,CAC9C,G,uCAED,WACI,IAAMgD,EAAMpB,IAAE,8BAA8BoB,MAC5C,QAASA,GAAO,MAAQA,CAC3B,G,8BAED,WACI,GAAIb,KAAKe,oBAAqB,CAC1B,IAAMC,EAAahB,KAAKR,UAAYQ,KAAKR,UAAUwB,WAAa,CAAC,EAC3DC,EAAWvB,SAASwB,iBAAiB,oCAQ3C,OAPID,GACAA,EAASE,SAAQ,SAACC,GACRA,EAAQC,QAAQL,IAClBA,EAAWI,EAAQC,MAAQD,EAAQnE,MAE1C,IAEE+D,CACV,CACD,OAAO,IACV,G,mBAED,WAAQ,MACJ,OAAOJ,SAAQ,UAACZ,KAAKX,YAAN,aAAC,EAAWiC,GAC9B,G,4BAED,WACI,OAAItB,KAAKR,UACEQ,KAAKR,UAAU+B,aAEnB9B,IAAE,yBAAyBoB,KACrC,K,EA9FC5B,CEHAuC,WAEF,aAAc,UACVxB,KAAKyB,OAAQC,EAAAA,EAAAA,cAChB,C,4BAED,SAAGC,EAAOC,GAAyB,IAAfC,EAAe,uDAAJ,GAC3B7B,KAAKyB,MAAMK,UAAUH,EAAO,SAAUC,EAAUC,EACnD,G,qBAED,SAAQF,GAAgB,6BAANI,EAAM,iCAANA,EAAM,mBACpB,EAAA/B,KAAKyB,OAAMO,SAAX,SAAoBL,GAApB,OAA8BI,GACjC,G,uBAED,SAAUJ,EAAOC,GAAyB,IAAfC,EAAe,uDAAJ,GAClC7B,KAAKyB,MAAMQ,UAAUN,EAAO,SAAUC,EAAUC,EACnD,G,0BAED,SAAaF,GAAgB,6BAANI,EAAM,iCAANA,EAAM,kBACzB,OAAO,EAAA/B,KAAKyB,OAAMS,aAAX,SAAwBP,GAAxB,OAAkCI,GAC5C,K,EApBCP,IFqGN,W","sources":["webpack://wcPPCP/webpack/bootstrap","webpack://wcPPCP/webpack/runtime/compat get default export","webpack://wcPPCP/webpack/runtime/define property getters","webpack://wcPPCP/webpack/runtime/hasOwnProperty shorthand","webpack://wcPPCP/webpack/runtime/make namespace object","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/classCallCheck.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/createClass.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/typeof.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js","webpack://wcPPCP/external window \"jQuery\"","webpack://wcPPCP/external window [\"wcPPCP\",\"utils\"]","webpack://wcPPCP/external window \"lodash\"","webpack://wcPPCP/external window [\"wp\",\"hooks\"]","webpack://wcPPCP/./assets/js/ppcp/product.js","webpack://wcPPCP/./node_modules/@babel/runtime/helpers/esm/inherits.js","webpack://wcPPCP/./assets/js/ppcp/event.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default function _defineProperty(obj, key, value) {\n  if (key in obj) {\n    Object.defineProperty(obj, key, {\n      value: value,\n      enumerable: true,\n      configurable: true,\n      writable: true\n    });\n  } else {\n    obj[key] = value;\n  }\n\n  return obj;\n}","export default function _classCallCheck(instance, Constructor) {\n  if (!(instance instanceof Constructor)) {\n    throw new TypeError(\"Cannot call a class as a function\");\n  }\n}","function _defineProperties(target, props) {\n  for (var i = 0; i < props.length; i++) {\n    var descriptor = props[i];\n    descriptor.enumerable = descriptor.enumerable || false;\n    descriptor.configurable = true;\n    if (\"value\" in descriptor) descriptor.writable = true;\n    Object.defineProperty(target, descriptor.key, descriptor);\n  }\n}\n\nexport default function _createClass(Constructor, protoProps, staticProps) {\n  if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n  if (staticProps) _defineProperties(Constructor, staticProps);\n  Object.defineProperty(Constructor, \"prototype\", {\n    writable: false\n  });\n  return Constructor;\n}","export default function _assertThisInitialized(self) {\n  if (self === void 0) {\n    throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n  }\n\n  return self;\n}","export default function _setPrototypeOf(o, p) {\n  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {\n    o.__proto__ = p;\n    return o;\n  };\n  return _setPrototypeOf(o, p);\n}","export default function _typeof(obj) {\n  \"@babel/helpers - typeof\";\n\n  return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) {\n    return typeof obj;\n  } : function (obj) {\n    return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n  }, _typeof(obj);\n}","import _typeof from \"./typeof.js\";\nimport assertThisInitialized from \"./assertThisInitialized.js\";\nexport default function _possibleConstructorReturn(self, call) {\n  if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n    return call;\n  } else if (call !== void 0) {\n    throw new TypeError(\"Derived constructors may only return object or undefined\");\n  }\n\n  return assertThisInitialized(self);\n}","export default function _getPrototypeOf(o) {\n  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {\n    return o.__proto__ || Object.getPrototypeOf(o);\n  };\n  return _getPrototypeOf(o);\n}","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"jQuery\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wcPPCP\"][\"utils\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"lodash\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wp\"][\"hooks\"];","import $ from 'jquery';\nimport {getSetting} from \"@ppcp/utils\";\nimport {isEqual} from 'lodash';\nimport Event from './event';\n\nclass Product extends Event {\n\n    constructor() {\n        super();\n        this.data = this.default_data = getSetting('product');\n        this.variation = false;\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));\n    }\n\n    needsShipping() {\n        return this.data?.needsShipping;\n    }\n\n    isVariationSelected() {\n        return !!this.variation;\n    }\n\n    onQuantityChange(e) {\n        if (e?.isTrigger) {\n            //cause a short delay so this won't execute before foundVariation\n            setTimeout(() => {\n                this.trigger('quantityChange', this.getQuantity(), this);\n            }, 50);\n        } else {\n            this.trigger('quantityChange', this.getQuantity(), this);\n        }\n    }\n\n    foundVariation(e, variation) {\n        this.variation = variation;\n        const prevData = {...this.data};\n        this.data = {\n            ...this.data, ...{\n                price: variation.display_price,\n                needsShipping: !variation.is_virtual\n            }\n        };\n        this.trigger('foundVariation', !isEqual(this.data, prevData), this);\n    }\n\n    resetVariationData() {\n        this.variation = null;\n        this.data = this.default_data;\n        this.trigger('resetVariation', this);\n    }\n\n    getQuantity() {\n        return parseInt($('[name=\"quantity\"]').val());\n    }\n\n    getPrice() {\n        return this.data?.price;\n    }\n\n    getTotal() {\n        return this.getQuantity() * this.getPrice();\n    }\n\n    isVariableProduct() {\n        return $('[name=\"variation_id\"]').length > 0;\n    }\n\n    isVariableProductSelected() {\n        const val = $('input[name=\"variation_id\"]').val();\n        return !!val && \"0\" !== val;\n    }\n\n    getVariationData() {\n        if (this.isVariableProduct()) {\n            const attributes = this.variation ? this.variation.attributes : {};\n            const elements = document.querySelectorAll('.variations [name^=\"attribute_\"]');\n            if (elements) {\n                elements.forEach((element) => {\n                    if (!(element.name in attributes)) {\n                        attributes[element.name] = element.value;\n                    }\n                });\n            }\n            return attributes;\n        }\n        return null;\n    }\n\n    getId() {\n        return parseInt(this.data?.id);\n    }\n\n    getVariationId() {\n        if (this.variation) {\n            return this.variation.variation_id;\n        }\n        return $('[name=\"variation_id\"]').val();\n    }\n}\n\nexport {Product};\nexport default Product;","import setPrototypeOf from \"./setPrototypeOf.js\";\nexport default function _inherits(subClass, superClass) {\n  if (typeof superClass !== \"function\" && superClass !== null) {\n    throw new TypeError(\"Super expression must either be null or a function\");\n  }\n\n  subClass.prototype = Object.create(superClass && superClass.prototype, {\n    constructor: {\n      value: subClass,\n      writable: true,\n      configurable: true\n    }\n  });\n  Object.defineProperty(subClass, \"prototype\", {\n    writable: false\n  });\n  if (superClass) setPrototypeOf(subClass, superClass);\n}","import {createHooks} from \"@wordpress/hooks\";\n\nclass Event {\n\n    constructor() {\n        this.hooks = createHooks();\n    }\n\n    on(event, callback, priority = 10) {\n        this.hooks.addAction(event, 'wcPPCP', callback, priority);\n    }\n\n    trigger(event, ...args) {\n        this.hooks.doAction(event, ...args);\n    }\n\n    addFilter(event, callback, priority = 10) {\n        this.hooks.addFilter(event, 'wcPPCP', callback, priority);\n    }\n\n    applyFilters(event, ...args) {\n        return this.hooks.applyFilters(event, ...args);\n    }\n\n}\n\nexport default Event;"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","_defineProperty","configurable","writable","_classCallCheck","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","_createClass","protoProps","staticProps","_assertThisInitialized","self","ReferenceError","_setPrototypeOf","p","setPrototypeOf","bind","__proto__","_typeof","iterator","constructor","_possibleConstructorReturn","_getPrototypeOf","getPrototypeOf","window","Product","subClass","superClass","create","data","default_data","getSetting","variation","$","document","body","on","onQuantityChange","foundVariation","resetVariationData","this","needsShipping","e","isTrigger","setTimeout","trigger","getQuantity","prevData","price","display_price","is_virtual","isEqual","parseInt","val","getPrice","isVariableProduct","attributes","elements","querySelectorAll","forEach","element","name","id","variation_id","Event","hooks","createHooks","event","callback","priority","addAction","args","doAction","addFilter","applyFilters"],"sourceRoot":""}