{"version":3,"file":"ProductInfoUpdater.js","names":["ProductInfoUpdater","a","setters","Component","default","deepMerge","on","off","execute","constructor","element","options","arguments","length","dataModelId","templateName","showOnProductUpdate","visibleProducts","replaceChildren","bindEvents","onProductUpdated","bind","initCache","classNames","hidden","event","model","detail","data","suppressRender","firstChild","removeChild","render","showTargetSelector","querySelector","indexOf","pid","classList","add","remove","destroy"],"sources":["components/product/ProductInfoUpdater.js"],"sourcesContent":["import Component from 'core/Component';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { on, off } from 'toolbox/event';\n\n/**\n * This is a description of the ProductInfoUpdater constructor function.\n * @class\n * @classdesc This is a description of the ProductInfoUpdater class. (must be edited)\n * @extends Component\n */\nexport default class ProductInfoUpdater extends Component {\n /**\n * Constructor of the class that mainly merge the options of the components\n * @param {HTMLElement} element HTMLElement of the component\n * @param {Object} options options that belongs to the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n dataModelId: null,\n templateName: null,\n showOnProductUpdate: false,\n visibleProducts: [],\n replaceChildren: false,\n }, options));\n }\n\n /**\n * Should contain only event listeners and nothing else\n * All the event handlers should be into a separated function. No usage of anonyous function\n */\n bindEvents() {\n on('product.updated', this.element, this.onProductUpdated.bind(this));\n }\n\n /**\n * Cache selectors\n */\n initCache() {\n this.classNames = {\n hidden: 'h-hidden',\n };\n }\n\n /**\n * Update component on product updated event\n *\n * @param {Object} event - event data\n */\n onProductUpdated(event) {\n if (this.options.showOnProductUpdate) {\n this.showOnProductUpdate(event);\n return;\n }\n\n const model = event.detail.data && event.detail.data[this.options.dataModelId];\n if (model) {\n if (model.suppressRender && this.options.replaceChildren) {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild);\n }\n } else if (this.options.templateName) {\n this.render(model, { replaceChildren: this.options.replaceChildren });\n }\n }\n }\n\n /**\n * Show or hide on product updated event\n *\n * @param {Object} event - event data\n */\n showOnProductUpdate(event) {\n const element = this.options.showTargetSelector\n ? this.element.querySelector(this.options.showTargetSelector)\n : this.element;\n\n if (this.options.visibleProducts.indexOf(event.detail.pid) !== -1) {\n element.classList.remove(this.classNames.hidden);\n } else {\n element.classList.add(this.classNames.hidden);\n }\n }\n\n /**\n * Destroy is called automatically after the component is being removed from the DOM\n * You must always destroy the listeners attached to an element to avoid any memory leaks\n */\n destroy() {\n off(this.element);\n }\n}\n"],"mappings":"yHAUqBA,CAAkB,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAVhCE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAS,CAAAJ,CAAA,CAATI,SAAS,WAAAJ,CAAA,EACTK,CAAE,CAAAL,CAAA,CAAFK,EAAE,CAAEC,CAAG,CAAAN,CAAA,CAAHM,GAAG,GAAAC,OAAA,SAAAA,CAAA,EAAAP,CAAA,WAQKD,CAAkB,CAAxB,aAAiC,CAAAG,CAAU,CAMtDM,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEL,CAAS,CAAC,CACrBS,WAAW,CAAE,IAAI,CACjBC,YAAY,CAAE,IAAI,CAClBC,mBAAmB,GAAO,CAC1BC,eAAe,CAAE,EAAE,CACnBC,eAAe,GACnB,CAAC,CAAEP,CAAO,CAAC,CACf,CAMAQ,UAAUA,CAAA,CAAG,CACTb,CAAE,CAAC,iBAAiB,CAAE,IAAI,CAACI,OAAO,CAAE,IAAI,CAACU,gBAAgB,CAACC,IAAI,CAAC,IAAI,CAAC,CACxE,CAKAC,SAASA,CAAA,CAAG,CACR,IAAI,CAACC,UAAU,CAAG,CACdC,MAAM,CAAE,UACZ,CACJ,CAOAJ,gBAAgBA,CAACK,CAAK,CAAE,CACpB,GAAI,IAAI,CAACd,OAAO,CAACK,mBAAmB,CAEhC,WADA,KAAI,CAACA,mBAAmB,CAACS,CAAK,CAAC,CAInC,KAAM,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