<div class="pb-4">
    <?php
    $args = array(
        'hide_empty' => 1,
        'taxonomy' => 'agenda-thematique'
    );
    $terms = get_terms($args);
    if (!empty($terms) && !is_wp_error($terms)) {
    ?>
        <div class="row mb-5">
            <div class=" list-filter input-group">
                <div class="input-group-prepend">
                    <label class="">Ou choisir une thématique: &nbsp;</label>
                </div>
                <form action="">
                    <?php
                    $count = count($terms);
                    echo '<select onchange="location = this.value;" id="rubrique-select" name="rubrique-select" class="custom-select">';
                    echo '<option value="' . get_bloginfo('url') . '/tout-lagenda/" selected>Toutes</option>';
                    foreach ($terms as $term) {
                        if (single_term_title('', false) == $term->name) {
                            echo '<option value="' . get_term_link($term) . '" selected>' . $term->name . '</option>';
                        } else {
                            echo '<option value="' . get_term_link($term) . '">' . $term->name . '</option>';
                        }
                    }
                    echo '</select>';
                    ?>
                </form>
            </div>
        </div>
    <?php
    }
    ?>
    <div class=" grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5">
        <?php
        global $agenda_query;
        $date = date('Ymd');
        $maPage = get_query_var('paged');
        $args_agenda = array(
            'post_type' => 'agenda',
            'post_status' => 'publish',
            'posts_per_page' => 9,
            'meta_key' => 'datedebut',
            'meta_query' => array(
                array(
                    'key' => 'datefin',
                    'value' => $date,
                    'compare' => '>=',
                ),
            ),
            'orderby' => 'meta_value',
            'order' => 'desc',
            'paged' => $maPage
        );
        if (isset($atts['cat']) && isset($atts['term']) && !empty($atts['term'])) {
            $args_agenda['tax_query'] = array(
                array(
                    'taxonomy' => $atts['cat'],
                    'field' => 'id',
                    'terms' => explode(',', $atts['term'])
                )
            );
        }
        $i = 0;
        $agenda_query = new WP_Query($args_agenda);
        if ($agenda_query->have_posts()) {
            $i = 0;
            while ($agenda_query->have_posts()) {
                $agenda_query->the_post();
                get_template_part('template-parts/components/card-agenda');
            }
            wp_reset_postdata();
        } else {
            echo '<p>Il n\'y a aucun evenement pour l\'instant</p>';
        }
        ?>
    </div>
    <?php get_template_part('template-parts/content/content-prev-next', array('prevText' => 'Date plus récentes', 'nextText' => 'Date plus anciennes')); ?>
</div>
</div>