<?php if (have_posts()) : ?>
  <section class="container blog-content">
    <?php while (have_posts()) : the_post(); ?>
      <article class="card-post item relative scroll-appear">
        <a href="<?php the_permalink(); ?>" itemprop="url">
          <div class="card-visual">
            <?php
            $thumb_import = get_field('thumb_import') ? get_field('thumb_import') : false;
            if ($thumb_import) {
              echo $thumb_import; ?>
              <meta itemprop="image" content="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'full')); ?>" />
            <?php
            } else { ?>
              <?php the_post_thumbnail('medium', ['class' => '', 'itemprop' => 'image']); ?>
            <?php
            } ?>
          </div>


          <div class="card-uptitle">
            <?php $categories = get_the_category();

            if (!empty($categories)) {
              echo '<span itemprop="articleSection">' . esc_html($categories[0]->name) . '</span>';
            } ?>
          </div>
          <h2 class="card-title" itemprop="headline"><?php echo esc_html(get_the_title()); ?></h2>
          <time class="card-date hidden" itemprop="datePublished" datetime="<?php echo esc_attr(get_the_date(DATE_W3C)); ?>"><?php echo esc_html(get_the_date('j F Y')); ?></time>
          <div class="card-text" itemprop="description"><?php the_excerpt(); ?></div>
          <button class="card-button ">
            <svg xmlns="http://www.w3.org/2000/svg" width="29" height="29" viewBox="0 0 29 29" fill="none">
              <circle cx="14.041" cy="14.8867" r="13.541" stroke="black" />
              <path d="M21.415 15.2403C21.6103 15.045 21.6103 14.7284 21.415 14.5332L18.233 11.3512C18.0378 11.1559 17.7212 11.1559 17.5259 11.3512C17.3307 11.5464 17.3307 11.863 17.5259 12.0583L20.3544 14.8867L17.5259 17.7151C17.3307 17.9104 17.3307 18.227 17.5259 18.4223C17.7212 18.6175 18.0378 18.6175 18.233 18.4223L21.415 15.2403ZM7.02051 15.3867H21.0615V14.3867H7.02051V15.3867Z" fill="black" />

            </svg>
            <span><?php echo __('En savoir plus', 'laurentperrier') ?></span>
          </button>
        </a>
      </article>

    <?php endwhile; ?>
  </section>
  <section class="wrapper blog-pagination">

    <?php

    // if (function_exists('pagination')) {
    //   global $wp_query;
    //   pagination($wp_query->max_num_pages);
    // }
    the_posts_pagination(array(
      'mid_size' => 3,
      'prev_text' => __('Previous', 'laurentperrier'),
      'next_text' => __('Next', 'laurentperrier'),
    ));


    // $big = 999999999; // Valeur arbitrairement élevée pour les paramètres 'total' et 'end_size'

    // echo paginate_links(array(
    //   'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
    //   'format' => '?paged=%#%',
    //   'current' => max(1, get_query_var('paged')),
    //   'total' => $wp_query->max_num_pages,
    //   'prev_next' => true,
    //   'prev_text' => __('Previous', 'laurentperrier'),
    //   'next_text' => __('Next', 'laurentperrier'),
    // ));

    ?>


  </section>
<?php
else :
  get_template_part('partials/content', 'none');
endif;
wp_reset_query(); ?>