/* JavaScript for FAQs on the front end. */

// eslint-disable-next-line no-undef
jQuery(document).ready(function ($) {
	// Note the wpgo_faq_data object is available, containing plugin url if needed. This was passed in via from PHP.

	//const toggleSpeed = 200;
	//const easing = 'swing';

	// Functionality for expandable FAQs.
	$(document.body).on('click', '.faq-expandable .faq-question', function () {
		const faqExpanded = this.getAttribute('aria-expanded');

		wp.hooks.doAction('ffaqs_accordion_mode', this);

		// Expand/collapse FAQ item clicked on.
		if (faqExpanded === 'true') {
			$(this).parent().removeClass('open');
			$(this).next().css('max-height', '0px');
			$(this).attr('aria-expanded', 'false');

			// Manually update the z-index value so icon hover for expanded state works correctly.
			$(this).find('.faq-expand-img.expanded').css('z-index', '5');
			$(this).find('.faq-expand-img.closed').css('z-index', '10');
		} else {
			const sh = $(this).next().prop('scrollHeight');
			$(this).parent().addClass('open');
			$(this)
				.next()
				.css('max-height', sh + 'px');
			$(this).attr('aria-expanded', 'true');

			// Manually update the z-index value so icon hover for expanded state works correctly.
			$(this).find('.faq-expand-img.expanded').css('z-index', '10');
			$(this).find('.faq-expand-img.closed').css('z-index', '5');
		}
	});
});
