{"version":3,"file":"Recommendations.js","names":["Recommendations","a","setters","Component","default","deepMerge","on","off","trigger","execute","constructor","element","options","arguments","length","selectors","section","quantity","data","providerData","initCache","closest","classes","hidden","bindEvents","onRecommendationsUpdate","bind","afterInit","bubbles","classList","remove","add","event","detail","items","timestamp","Date","getTime","zone","reload","JSON","stringify","destroy"],"sources":["components/global/Recommendations.js"],"sourcesContent":["import Component from 'core/Component';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { on, off, trigger } from 'toolbox/event';\n\n/**\n * This is a description of the Recommendations constructor function.\n * @class\n * @classdesc This is a description of the Recommendations class. (must be edited)\n * @extends Component\n */\nexport default class Recommendations 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 selectors: {\n section: '.c-section',\n },\n // This is the quantity of recommendations loaded from the server.\n // Might be 0 if the recommendation provider load recommendations client-side\n quantity: 0,\n // This is the object that contains the recommendations items\n // and other values used by the provider to understand the context of the page\n data: {},\n // This is the specific details coming from the provider configuration\n providerData: {},\n\n }, options));\n }\n\n /**\n * All selectors must be cached. Never cache elements that are out of the component scope\n */\n initCache() {\n this.selectors.section = this.element.closest(this.selectors.section);\n\n this.classes = {\n hidden: 'h-hidden',\n };\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('recommendations.update', this.element, this.onRecommendationsUpdate.bind(this));\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n * @emits recommendations.init event\n */\n afterInit() {\n trigger('recommendations.init', this.element, {\n bubbles: true,\n element: this.element,\n data: this.options,\n });\n\n if (this.selectors.section) {\n if (this.options.quantity > 0) {\n this.selectors.section.classList.remove(this.classes.hidden);\n } else {\n this.selectors.section.classList.add(this.classes.hidden);\n }\n } else if (this.options.quantity > 0) {\n this.element.classList.remove(this.classes.hidden);\n } else {\n this.element.classList.add(this.classes.hidden);\n }\n }\n\n /**\n * @listens recommendations.update event\n * @param {Object} event recommendations\n */\n onRecommendationsUpdate(event) {\n const { detail: { data } } = event;\n this.options.data.items = data;\n this.options.data.timestamp = (new Date()).getTime();\n this.options.data.zone = this.options.providerData.zone;\n this.reload({\n data: JSON.stringify(this.options.data),\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('recommendations.update', this.element);\n }\n}\n"],"mappings":"2HAUqBA,CAAe,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAV7BE,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,CAAEC,CAAO,CAAAP,CAAA,CAAPO,OAAO,GAAAC,OAAA,SAAAA,CAAA,EAAAR,CAAA,WAQJD,CAAe,CAArB,aAA8B,CAAAG,CAAU,CAMnDO,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEN,CAAS,CAAC,CACrBU,SAAS,CAAE,CACPC,OAAO,CAAE,YACb,CAAC,CAGDC,QAAQ,CAAE,CAAC,CAGXC,IAAI,CAAE,CAAC,CAAC,CAERC,YAAY,CAAE,CAAC,CAEnB,CAAC,CAAEP,CAAO,CAAC,CACf,CAKAQ,SAASA,CAAA,CAAG,CACR,IAAI,CAACL,SAAS,CAACC,OAAO,CAAG,IAAI,CAACL,OAAO,CAACU,OAAO,CAAC,IAAI,CAACN,SAAS,CAACC,OAAO,CAAC,CAErE,IAAI,CAACM,OAAO,CAAG,CACXC,MAAM,CAAE,UACZ,CACJ,CAMAC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