{"version":3,"file":"WhatsApp.js","names":["WhatsApp","a","setters","Component","default","deepMerge","on","cookie","execute","constructor","element","options","arguments","length","analytics","dataLayerContainer","initCache","selectors","closeButton","showCloseBtn","querySelectorAll","afterInit","getCookie","setClosePopupCookie","classList","remove","bindEvents","onClick","bind","closePopup","window","push","e","preventDefault","stopPropagation","add","expDate","Date","setMinutes","getMinutes","document","toUTCString"],"sources":["components/global/WhatsApp.js"],"sourcesContent":["import Component from 'core/Component';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { on } from 'toolbox/event';\nimport { cookie } from 'toolbox/cookie';\n\n/**\n * WhatsApp component handles datalayer push of analytics info\n * @class\n * @classdesc If analytics info is present, component will push when user will click on the link\n * @extends Component\n */\nexport default class WhatsApp 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 analytics: {},\n dataLayerContainer: 'dataLayer',\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 super.initCache();\n this.selectors.closeButton = this.options.showCloseBtn ? this.element.querySelectorAll('.whatsapp-chat-close') : null;\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n if (this.options.showCloseBtn && cookie.getCookie('whatsapp-popup-closed')) {\n this.setClosePopupCookie();\n } else {\n this.element.classList.remove('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('click', this.element, this.onClick.bind(this));\n if (this.selectors.closeButton) {\n on('click', this.selectors.closeButton, this.closePopup.bind(this));\n }\n }\n\n /**\n * Send analytics event on the click of link\n */\n onClick() {\n if (this.options.analytics) {\n const dataLayerContainer = window[this.options.dataLayerContainer];\n if (dataLayerContainer) {\n dataLayerContainer.push(this.options.analytics);\n }\n }\n }\n\n /**\n * Closes popup\n * @param {Object} e - Event object\n */\n closePopup(e) {\n e.preventDefault();\n e.stopPropagation();\n\n this.element.classList.add('h-hidden');\n this.setClosePopupCookie();\n }\n\n /**\n * sets a 30min cookie for hiding popup after its closing\n */\n setClosePopupCookie() {\n const expDate = new Date();\n expDate.setMinutes(expDate.getMinutes() + 30);\n document.cookie = `whatsapp-popup-closed=true;expires=${expDate.toUTCString()};path=/`;\n }\n}\n"],"mappings":"0IAWqBA,CAAQ,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAXtBE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAS,CAAAJ,CAAA,CAATI,SAAS,WAAAJ,CAAA,EACTK,CAAE,CAAAL,CAAA,CAAFK,EAAE,WAAAL,CAAA,EACFM,CAAM,CAAAN,CAAA,CAANM,MAAM,GAAAC,OAAA,SAAAA,CAAA,EAAAP,CAAA,WAQMD,CAAQ,CAAd,aAAuB,CAAAG,CAAU,CAM5CM,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,SAAS,CAAE,CAAC,CAAC,CACbC,kBAAkB,CAAE,WACxB,CAAC,CAAEJ,CAAO,CAAC,CACf,CAKAK,SAASA,CAAA,CAAG,CACR,KAAK,CAACA,SAAS,CAAC,CAAC,CACjB,IAAI,CAACC,SAAS,CAACC,WAAW,CAAG,IAAI,CAACP,OAAO,CAACQ,YAAY,CAAG,IAAI,CAACT,OAAO,CAACU,gBAAgB,CAAC,sBAAsB,CAAC,CAAG,IACrH,CAMAC,SAASA,CAAA,CAAG,CACJ,IAAI,CAACV,OAAO,CAACQ,YAAY,EAAIZ,CAAM,CAACe,SAAS,CAAC,uBAAuB,CAAC,CACtE,IAAI,CAACC,mBAAmB,CAAC,CAAC,CAE1B,IAAI,CAACb,OAAO,CAACc,SAA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