<?php

global $campoal_options;
global $post;

$posts_per_page = isset($campoal_options['conikal_petitions_per_page_field']) ? $campoal_options['conikal_petitions_per_page_field'] : '';

$searched_posts = conikal_search_petitions($post->ID);
$total          = $searched_posts->found_posts;

if($searched_posts->have_posts()) : ?>
    <div class="ui three stackable cards petition-cards">
        <?php while($searched_posts->have_posts() ) : $searched_posts->the_post();
            /*
             * Include the petition template for the content.
             * If you want to override this in a child theme, then include a file
             */
            get_template_part('loop/content-petition', 'grid');

        endwhile; ?>
    </div>

    <!-- PAGINATION -->
    <div class="ui hidden divider"></div>
    <?php conikal_pagination_buttons(_n('Petition', 'Petitions', $total, 'campoal'), $searched_posts->max_num_pages, $total, $posts_per_page) ?>
<?php else : 

    $searched_posts = conikal_search_petitions($post->ID, 'WORLD');
    $total = $searched_posts->found_posts;

    if($searched_posts->have_posts()) :
        conikal_not_found_post(__('The country you selected has no campaigns found.', 'campoal'), __("No campaigns in your country, global campaigns are shown instead.", 'campoal'), 'warning', 'globe icon');
        ?>
        <div class="ui section hidden divider"></div>
        <div class="ui three stackable cards petition-cards">
            <?php while($searched_posts->have_posts() ) : $searched_posts->the_post();
                /*
                 * Include the petition template for the content.
                 * If you want to override this in a child theme, then include a file
                 */
                get_template_part('loop/content-petition', 'grid');
    
            endwhile; ?>
        </div>
    
        <!-- PAGINATION -->
        <div class="ui hidden divider"></div>
        <?php conikal_pagination_buttons(_n('Petition', 'Petitions', $total, 'campoal'), $searched_posts->max_num_pages, $total, $posts_per_page) ?>
    <?php else : 
        conikal_not_found_post(__('No campaigns found.', 'campoal'), __("We're sorry, but no campaigns matched your criteria.", 'campoal'));
    endif;
endif;
?>
<div class="ui section hidden divider"></div>