<?php
$query =  new WP_Query(array(
	'post_type' => 'revues',
	'orderby' => 'date',
	'order' => 'DESC',
	'offset' => 1,
	'post_status' => 'publish',
));
?>
<section class="block-revues-precedentes alignfull" <?php echo get_block_wrapper_attributes(); ?>>
	<div class="block-revues-precedentes__inner">

		<div class="block-revues-precedentes__header">
			<h2 class="block-title">À découvrir</h2>
			<h3 class="block-subtitle">Lisez nos revues précédentes</h3>
		</div>

		<div class="block-revues-precedentes__slider-content">
			<?php if ($query->have_posts()) : ?>
				<div class="swiper revues-precedentes-swiper">
					<div class="swiper-wrapper">
						<?php while ($query->have_posts()) : $query->the_post(); ?>
							<?php
							$issue_number = get_field('issue_number', get_the_ID());
							$is_multiple_issue_number = $issue_number && is_numeric($issue_number) && strpos($issue_number, '.') !== false;
							?>
							<article class="card-revue swiper-slide">
								<div class="content-meta">
									<span class="content-meta__type content-meta__type--revue">Revue</span>
									<?php if ($is_multiple_issue_number) : ?>

										<!-- Contenu pour les numéros d'issue à virgule -->
										<div class="issue-number-group">
											<?php
											$issue_number_parts = explode('.', $issue_number);

											?>
											<p class="label">Numéro</p>
											<?php foreach ($issue_number_parts as $issue_number) : ?>

												<div class="content-meta__issue-number">
													<?php if (isset($issue_number) && is_numeric($issue_number)) : ?>
														<p class="value">
															<?php echo $issue_number ?>
														</p>
													<?php endif; ?>
												</div>
											<?php endforeach; ?>
										</div>
									<?php else : ?>
										<div class=" content-meta__issue-number">
											<p class="label">Numéro</p>
											<p class="value">
												<?php echo get_field('issue_number', get_the_ID()); ?>
											</p>
										</div>
									<?php endif; ?>
								</div>
								<div class="card-revue__content">
									<h4 class="card-revue__title title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
									<!-- <h5 class="card-revue__edito-title edito-title">Édito</h5> -->
									<div class="card-revue__excerpt">
										<?php
										// echo wp_trim_words(get_the_excerpt(), 45, '...'); 
										?>
									</div>

									<div class="card-revue__post-details">

										<div class="card-revue__parution">
											<p class="card-revue__parution__label label"><?php echo __('Parution', 'dynamiques'); ?></p>
											<time class="card-revue__parution__date">
												<?php echo get_the_date('d F Y'); ?>
											</time>
										</div>

									</div>
								</div>

								<div class="card-revue__issue-thumbnail-wrapper">
									<div class="card-revue__issue-thumbnail">
										<?php if (has_post_thumbnail()) : ?>
											<?php
											$focal_position = safe_get_thumbnail_focal_point_css();
											echo get_the_post_thumbnail(get_the_ID(), 'full', [
												'style' => 'object-fit: cover; object-position: ' . esc_attr($focal_position) . ';'
											]);
											?>
										<?php endif; ?>
									</div>
									<div class="card-background"></div>
								</div>


							</article>
						<?php endwhile; ?>
					</div>

					<!-- <div class="swiper-pagination-fraction"></div> -->
					<div class="swiper-pagination"></div>
					<div class="swiper-actions-wrapper">

						<div class="swiper-controls">
							<div class="swiper-button-prev">
								<?php
								$previous_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-previous.svg';
								if (file_exists($previous_arrow_icon)) {
									echo file_get_contents($previous_arrow_icon);
								}
								?>

							</div>
							<div class="swiper-button-next">
								<?php
								$next_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-next.svg';
								if (file_exists($next_arrow_icon)) {
									echo file_get_contents($next_arrow_icon);
								}
								?>
							</div>
						</div>
						<a id="discover-all-revues" href="<?php echo get_post_type_archive_link('revues'); ?>">
							Découvrir nos revues précédentes
						</a>
					</div>
				</div>
			<?php endif; ?>
		</div>
	</div>
</section>