<?php
/**
 * Template 7 - Dark Theme FAQ
 * @package     wp-faq-block
 * @since 1.0.0
 */

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

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
?>

<div class="faq-plugin-wrapper">
	<div class="wpfaqblock-t7-wrapper <?php echo esc_attr($args['faqtheme']); ?> <?php echo esc_attr($args['class']); ?>">

		<?php if ($args['title']) { ?>
			<h2 class="wpfaqblock-t7-title"><?php echo esc_html($args['title']); ?></h2>
		<?php } ?>

		<?php if ($args['search']) { ?>
			<form action="?" method="get" class="wpfaqblock-t7-search-form">
				<?php wp_nonce_field( 'wpfaqblock_search' ); ?>
				<div class="input-group">
					<input type="text" class="input-text" placeholder="<?php echo esc_attr($args['placeholder']); ?>"
						name="wpfaqblocksearch" value="<?php
						if (isset($_GET['wpfaqblocksearch']) && isset($_GET['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'wpfaqblock_search')) {
							echo esc_attr(trim(sanitize_text_field(wp_unslash($_GET['wpfaqblocksearch']))));
						}
						?>">
					<button class="search-btn" type="submit"><?php echo esc_html__('Search', 'wpfaqblock'); ?></button>
				</div>
			</form>
		<?php } ?>

		<?php if ($query->have_posts()) { ?>
			<div class="wpfaqblock-t7-list">
				<?php
				$item_count = 0;
				while ($query->have_posts()) {
					$query->the_post();
					$is_open = $this->is_item_open($args, $query);
					$item_count++;
					?>
					<div id="<?php echo esc_attr( apply_filters( 'wpfaqblock_faq_item_id', '', get_the_ID() ) ); ?>" class="wpfaqblock-t7-item <?php echo $is_open ? 'wpfaqblock-t7-item-open' : ''; ?>">
						<div class="wpfaqblock-t7-question">
							<span><?php echo esc_html(get_the_title()); ?></span>
								<button class="wpfaqblock-t7-btn" aria-expanded="<?php echo $is_open ? 'true' : 'false'; ?>">
						<?php
						$custom_icon_html = $this->render_custom_icons($args);
						if ($custom_icon_html) {
							echo wp_kses_post($custom_icon_html);
						} else {
						$icon_style = isset($args['faqicon']) ? $args['faqicon'] : 'plus';
						switch ($icon_style) {
							case 'arrow':
								echo '<svg class="wpfaqblock-t7-icon-plus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>';
								echo '<svg class="wpfaqblock-t7-icon-minus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>';
								break;
							case 'chevron':
								echo '<svg class="wpfaqblock-t7-icon-plus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>';
								echo '<svg class="wpfaqblock-t7-icon-minus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>';
								break;
							case 'modern':
								echo '<svg class="wpfaqblock-t7-icon-plus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>';
								echo '<svg class="wpfaqblock-t7-icon-minus" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>';
								break;
							case 'circle':
								echo '<svg class="wpfaqblock-t7-icon-plus" width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>';
								echo '<svg class="wpfaqblock-t7-icon-minus" width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="8" y1="12" x2="16" y2="12"/></svg>';
								break;
							case 'plus':
							default:
								echo '<svg class="wpfaqblock-t7-icon-plus" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>';
								echo '<svg class="wpfaqblock-t7-icon-minus" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="5" y1="12" x2="19" y2="12"/></svg>';
								break;
						}
						}
						?>
							</button>
						</div>
						<div class="wpfaqblock-t7-answer" <?php echo !$is_open ? 'style="display:none;"' : ''; ?>>
							<?php
							$content = get_the_content();
							echo wp_kses_post(apply_filters('the_content', $content));
							echo apply_filters( 'wpfaqblock_item_content_end', '', get_post(), $args );
							?>
						</div>
					</div>
				<?php } ?>
				<?php wp_reset_postdata(); ?>
			</div>
		<?php } else { ?>
			<p class="wpfaqblock-t7-noresults"><?php echo esc_html__('No FAQs found.', 'wpfaqblock'); ?></p>
		<?php } ?>
	</div>
</div>



