<?php

$initialPostDisplayAmount = 10;

$anchor = $attributes['anchor'] ?? false;

$args = array(
	'post_type' => 'dbmob',
	'posts_per_page' => $initialPostDisplayAmount,
);
$query = new WP_Query($args);
$post_count = $query->found_posts;
?>
<section <?php echo get_block_wrapper_attributes(array('class' => '', 'id' => $anchor)); ?>>
	<h2>Les notices rédigées par le CARHOP</h2>

	<div class="notices-toolbar" data-post-type="dbmob">
		<h2 class="post-count">
			<span class="post-count__count">
				<?php echo $post_count; ?>
			</span>
			<span class="post-count__text">
				<?php _e('notices biographiques', 'carhop-blocks'); ?>
			</span>
		</h2>

		<select class="sort_by" name="sort_by" id="sort_by">
			<option value="date_desc" selected><?php _e('Voir les dernières notices en premier', 'carhop-blocks'); ?></option>
			<option value="date_asc"><?php _e('Voir les plus anciennes notices en premier', 'carhop-blocks'); ?></option>
		</select>


		<div class="search-bar">
			<label for="search-input"><?php _e('Rechercher une notice par nom', 'carhop-blocks'); ?></label>
			<input type="text" placeholder="<?php _e('Rechercher par nom', 'carhop-blocks'); ?>" name="search">
		</div>
	</div>

	<?php if ($query->have_posts()) : ?>
		<div class="dbmob-grid">
			<?php while ($query->have_posts()) : $query->the_post(); ?>
				<?php get_template_part('template-parts/components/cards/post-card', null, array(
					'ID'                => get_the_ID(),
					'current_post_type' => 'dbmob',
				)); ?>
			<?php endwhile; ?>
		</div>
		<?php wp_reset_postdata(); ?>
	<?php endif; ?>

	<?php if ($post_count > $initialPostDisplayAmount) : ?>
		<button class="load-more-button" data-offset="0" data-posts-per-page="-1">Afficher plus</button>
	<?php endif; ?>




</section>