<?php

/**
 * Layout: Grid.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$columns = (int) $attributes['columns'];

// Render HTML output
if ( $aiopod_query->have_posts() ) : ?>
    <div class="aiopod aiopod-podcasts aiopod-podcasts--layout-grid">
        <!-- Title -->
        <?php if ( ! empty( $attributes['title'] ) ) : ?>
            <div class="aiopod-podcasts__title aiopod-text-heading">
                <?php echo esc_html( $attributes['title'] ); ?>
            </div>
        <?php endif; ?>
        
        <!-- Count -->
        <?php if ( ! empty( $attributes['show_count'] ) ) : ?>
            <div class="aiopod-podcasts__count aiopod-text-muted">
                <?php 
                $podcasts_count = (int) $attributes['count'];

                echo sprintf( 
                    _n( '%s podcast found.', '%s podcasts found.', $podcasts_count, 'aio-podcast-studio' ), 
                    number_format_i18n( $podcasts_count ) 
                );
                ?>
            </div>
        <?php endif; ?>

        <!-- Podcasts -->
        <div class="aiopod-podcasts__list aiopod-responsive-wrapper">
            <div class="aiopod-grid aiopod-col-<?php echo esc_attr( $columns ); ?> aiopod-dynamic-wrapper">
                <?php
                // Start the loop
                global $post;

                // The loop          
                while ( $aiopod_query->have_posts() ) :        
                    $aiopod_query->the_post();  
                    aiopod_the_podcast_card( $post, $attributes );       
                endwhile;
                    
                // Use reset postdata to restore orginal query
                wp_reset_postdata();   
                ?>
            </div>
        </div>

        <!-- Pagination -->
        <?php aiopod_the_pagination( $attributes ); ?>
    </div>
<?php elseif ( 0 === (int) $attributes['hide_if_empty'] ) : ?>
    <div class="aiopod aiopod-podcasts aiopod-podcasts--layout-grid">
        <div class="aiopod-podcasts__empty aiopod-text-muted">
            <?php esc_html_e( 'No podcasts found.', 'aio-podcast-studio' ); ?>
        </div>
    </div>
<?php endif;
