<?php
/**
 * Public FAQ accordion section.
 *
 * @package Lucrativeit_Subscription_Recurring_Billing
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Included template; variables are local to the including scope.

$instance_id = isset( $instance_id ) ? $instance_id : 'lucrsure-faq';
$heading     = isset( $heading ) ? $heading : '';
$subtitle    = isset( $subtitle ) ? $subtitle : '';
$items       = isset( $items ) ? lucrsure_normalize_faq_items( $items ) : array();
?>

<section class="lucrsure-faq" id="<?php echo esc_attr( $instance_id ); ?>">
	<?php if ( $heading || $subtitle ) : ?>
		<header class="lucrsure-faq-header">
			<?php if ( $heading ) : ?>
				<h2 class="lucrsure-faq-title"><?php echo esc_html( $heading ); ?></h2>
			<?php endif; ?>
			<?php if ( $subtitle ) : ?>
				<p class="lucrsure-faq-subtitle"><?php echo esc_html( $subtitle ); ?></p>
			<?php endif; ?>
		</header>
	<?php endif; ?>

	<div class="lucrsure-faq-list" role="list">
		<?php foreach ( $items as $index => $item ) : ?>
			<div class="lucrsure-faq-item" role="listitem">
				<button
					type="button"
					class="lucrsure-faq-question"
					id="<?php echo esc_attr( $instance_id . '-q-' . $index ); ?>"
					aria-expanded="false"
					aria-controls="<?php echo esc_attr( $instance_id . '-a-' . $index ); ?>"
				>
					<span><?php echo esc_html( $item['question'] ); ?></span>
					<span class="lucrsure-faq-icon" aria-hidden="true"></span>
				</button>
				<div
					class="lucrsure-faq-answer"
					id="<?php echo esc_attr( $instance_id . '-a-' . $index ); ?>"
					role="region"
					aria-labelledby="<?php echo esc_attr( $instance_id . '-q-' . $index ); ?>"
					hidden
				>
					<p><?php echo esc_html( $item['answer'] ); ?></p>
				</div>
			</div>
		<?php endforeach; ?>
	</div>
</section>
