const initFlashMessages = (flashMessageSelector, closeButtonSelector) => {
    const closeBtns = document.querySelectorAll(closeButtonSelector);
	for(const closeBtn of closeBtns) {
		closeBtn.addEventListener('click', () => {
			const fm = closeBtn.closest('.flash-message');
			fm.classList.add('flash-message--hidden');
		});
	};

	const flashMessages = document.querySelectorAll(flashMessageSelector);
	if(flashMessages.length) {
		setTimeout(() => {
            for(const fm of flashMessages) {
                if(fm.getAttribute('data-hide')) {
					fm.classList.add('flash-message--hidden');
				}
            }
		}, 5000);
	}
}

export {
  initFlashMessages
}