<?php
$sidebar = false; $cols = 'col';
if ( is_active_sidebar('sidebar') && ! get_theme_mod('sarahlist_blog_hide_sidebar') ) {
    $sidebar = true;
}

if ( $sidebar ) {
    $cols = 'col-md-7 col-lg-8 col-xl-9';
}

$blog_class = $sidebar ? 'has-sidebar' : 'no-sidebar';

$args = array();
if ( $sidebar ) {
    $args['sizes'] = '(min-width: 1200px) 500px, (min-width: 992px) 616px, (min-width: 768px) 396px, (min-width: 576px) 516px, calc( 100vw - 24px )';
} else {
    $args['sizes'] = '(min-width: 992px) 936px, (min-width: 768px) 696px, (min-width: 576px) 516px, calc( 100vw - 24px )';
}
?>
<div class="row">
    <div class="<?php echo esc_attr( $cols ); ?>">
        <?php
            do_action( 'sarahlist_before_blog_loop' );
        ?>
        <div class="sarahlist-blog blog-list <?php echo esc_attr( $blog_class ); ?>">
            <div class="row">
            <?php
                if ( have_posts() ) {
                    while ( have_posts() ) {
                        the_post();                        
                        ?>
                        <article <?php post_class( 'post-list col-md-12' ); ?>>
                            <div class="post-inner">
                                <?php
                                    $image_url = wp_get_attachment_url( get_post_thumbnail_id() );                                    
                                    if ( $image_url ) {
                                        ?>
                                        <div class="post-format post-thumbnails">
                                            <a href="<?php the_permalink(); ?>">
                                                <?php the_post_thumbnail( 'full', $args ); ?>
                                            </a>
                                        </div>
                                        <?php
                                    }
                                ?>
                                <div class="post-details sarahlist-box">
                                    <div>
                                        <?php if ( ! get_theme_mod( 'sarahlist_post_hide_category' ) ) { ?>
                                        <div class="cat-links"><?php the_category(', '); ?></div>
                                        <?php } ?>
                                        <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        <?php
                                            get_template_part( 'template-parts/post', 'meta' );
                                        ?>
                                        <div class="entry-excerpt">
                                            <p><?php echo wp_trim_words( get_the_excerpt(), 20, '...' ); ?></p>
                                            <a href="<?php the_permalink(); ?>" class="more-link">
                                                <?php echo esc_html__( 'Continue Reading', 'sarahlist' ); ?>&nbsp;&rarr;
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </article>
                        <?php
                    }
                } else {
                    get_template_part( 'template-parts/post', 'none' );
                }
            ?>
            </div>
            <?php sarahlist_site_pagination(); ?>
        </div>
        <?php
            do_action( 'sarahlist_after_blog_loop' );
        ?>
    </div>
    <?php if ( $sidebar ) { ?>
    <div class="col-md-5 col-lg-4 col-xl-3">
        <?php get_sidebar(); ?>
    </div>
    <?php } ?>
</div>