{"version":3,"file":"ContentPanel.js","names":["ContentPanel","a","setters","Component","default","Event","on","off","transition","cookie","deepMerge","execute","constructor","element","options","arguments","length","classNames","closedState","hidden","hasCloseIcon","type","onCloseCookieId","closeTimeout","hideAnimationDelay","eventName","defaultMessage","initCache","selectors","closeButton","querySelector","content","initState","state","isVisible","classList","contains","afterInit","timeout","setDisplayDelay","add","emit","bindEvents","onCloseClick","bind","concat","show","hide","onPanelTransitionEnd","e","preventDefault","setCookie","data","addContent","setContentType","remove","setAttribute","clearTimeout","setTimeout","innerHTML","dataAnalytics","onClose","destroy","removeListener"],"sources":["components/global/ContentPanel.js"],"sourcesContent":["import Component from 'core/Component';\nimport { Event } from 'services/EventEmitter';\nimport { on, off } from 'toolbox/event';\nimport { transition } from 'toolbox/animate';\nimport { cookie } from 'toolbox/cookie';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * This is a description of the ContentPanel constructor function.\n * @class\n * @classdesc This is a description of the ContentPanel class.\n * @extends Component\n */\nexport default class ContentPanel 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            classNames: {\n                closedState: 'm-closed',\n                hidden: 'h-hidden',\n                hasCloseIcon: 'm-has-close-icon',\n            },\n            type: null,\n            onCloseCookieId: null,\n            closeTimeout: 0, // Delay before the panel automatically close (in milliseconds)\n            hideAnimationDelay: 500, // Time needed for close animation\n            eventName: 'contentPanel', // Potentially, we could have many instances of contentPanel but they do not respond\n            defaultMessage: null, // string - default message in case no content is passed\n            // to the same event depending on the context (cookie, error message, promo)\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.closeButton = this.element.querySelector('[data-js-close]');\n        this.selectors.content = this.element.querySelector('[data-js-content]');\n    }\n\n    /**\n     * Init the different state of the component\n     * It helps to avoid heavy DOM manipulation\n     */\n    initState() {\n        this.state.type = null;\n        this.state.isVisible = !this.element.classList.contains(this.options.classNames.closedState);\n    }\n\n    /**\n     * After init\n     * Run any script after the component is fully initialized\n     */\n    afterInit() {\n        this.timeout = null;\n        this.setDisplayDelay();\n        if (this.element.querySelector('.c-content-panel__close')) {\n            this.element.classList.add(this.options.classNames.hasCloseIcon);\n        }\n        Event.emit('remindertooltip.update');\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        if (this.selectors.closeButton) {\n            on('click', this.selectors.closeButton, this.onCloseClick.bind(this));\n        }\n\n        Event.on(`${this.options.eventName}.show`, this.show, this);\n        Event.on(`${this.options.eventName}.hide`, this.hide, this);\n        transition(this.element, this.onPanelTransitionEnd.bind(this));\n    }\n\n    /**\n     * CloseClick event handler\n     *\n     * @param {Object} e Event object\n     */\n    onCloseClick(e) {\n        e.preventDefault();\n        if (this.options.onCloseCookieId) {\n            cookie.setCookie(this.options.onCloseCookieId, true);\n        }\n        this.hide();\n    }\n\n    /**\n     * We can display the content panel with dynamic content or just display content already present from server\n     *\n     * @param {Object} data Data\n     */\n    show(data = {}) {\n        const { type, closeTimeout } = data;\n\n        const content = data.content || this.options.defaultMessage;\n\n        this.setDisplayDelay(closeTimeout);\n\n        if (content) {\n            this.addContent(content);\n        }\n        this.setContentType(type);\n\n        if (!this.state.isVisible) {\n            this.element.classList.remove(this.options.classNames.closedState);\n            this.element.classList.remove(this.options.classNames.hidden);\n            this.element.setAttribute('aria-hidden', 'false');\n            this.state.isVisible = true;\n        }\n\n        Event.emit('remindertooltip.update');\n    }\n\n    /**\n     * Set display delay\n     *\n     * @param {Integer} closeTimeout - expressed in milliseconds\n     */\n    setDisplayDelay(closeTimeout = this.options.closeTimeout) {\n        // If closeTimeout is defined then the panel will close automatically after the defined timeout\n        if (closeTimeout > 0) {\n            if (this.timeout) {\n                clearTimeout(this.timeout);\n            }\n            this.timeout = setTimeout(this.hide.bind(this), closeTimeout);\n        }\n    }\n\n    /**\n     * Set the type of the content. It can be \"success\", \"warning\", \"info\", \"error\"\n     *\n     * @param {String} type of content\n     */\n    setContentType(type = this.options.type) {\n        // do not need to update if current type is already the same\n        if (this.state.type === type) {\n            return;\n        }\n\n        if (type) {\n            this.element.setAttribute('data-type', type);\n            this.state.type = type;\n        } else if (this.state.type) {\n            // If previous data-type was defined, we need to remove it to avoid keeping previous state.\n            this.element.setAttribute('data-type', '');\n            this.state.type = null;\n        }\n    }\n\n    /**\n     * Add content HTML content in the content panel\n     *\n     * @param {String} content for content panel\n     */\n    addContent(content) {\n        if (content) {\n            this.selectors.content.innerHTML = content;\n        }\n    }\n\n    /**\n     * Hide the content panel\n     */\n    hide() {\n        this.element.classList.add(this.options.classNames.closedState);\n        setTimeout(() => {\n            this.element.classList.add(this.options.classNames.hidden);\n            this.element.setAttribute('aria-hidden', 'true');\n            Event.emit('remindertooltip.update');\n        }, this.options.hideAnimationDelay);\n        if (this.options.dataAnalytics && this.options.dataAnalytics.onClose) {\n            Event.emit('analytics.event', this.options.dataAnalytics.onClose);\n        }\n        this.state.isVisible = false;\n    }\n\n    /**\n     * PanelTransitionEnd event handler\n     */\n    onPanelTransitionEnd() {\n        Event.emit(`${this.options.eventName}.transition.ended`);\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('click', this.selectors.closeButton);\n        Event.removeListener(`${this.options.eventName}.show`, this.show, this);\n        Event.removeListener(`${this.options.eventName}.hide`, this.hide, this);\n    }\n}\n"],"mappings":"0LAaqBA,CAAY,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAb1BE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAK,CAAAJ,CAAA,CAALI,KAAK,WAAAJ,CAAA,EACLK,CAAE,CAAAL,CAAA,CAAFK,EAAE,CAAEC,CAAG,CAAAN,CAA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