<?php 
/**
 * Template part for displaying Highlights Section
 *
 *@package Magazine Bell
 */
$highlights_title       = magazine_bell_get_option( 'highlights_title' );
$highlights_subtitle       = magazine_bell_get_option( 'highlights_subtitle' );
$highlights_content_type   = magazine_bell_get_option( 'highlights_content_type' );
$number_of_highlights_items = magazine_bell_get_option( 'number_of_highlights_items' );
$highlights_layout = magazine_bell_get_option( 'highlights_layout_option' );
$highlights_column = magazine_bell_get_option( 'number_of_highlights_column' );
$highlights_category = magazine_bell_get_option( 'highlights_category' );
$enable_content     = magazine_bell_get_option( 'highlights_content_enable' );
$enable_title     = magazine_bell_get_option( 'highlights_title_enable' );
$enable_category     = magazine_bell_get_option( 'highlights_category_enable' );
$enable_posted_on     = magazine_bell_get_option( 'highlights_posted_on_enable' );
$enable_author     = magazine_bell_get_option( 'highlights_author_enable' );
$highlights_speed   = magazine_bell_get_option( 'highlights_speed' );
$highlights_dot   = magazine_bell_get_option( 'highlights_dot' );
$highlights_arrow   = magazine_bell_get_option( 'highlights_arrow_enable' );
$highlights_autoplay  = magazine_bell_get_option( 'highlights_autoplay_enable' );
$highlights_infinite  = magazine_bell_get_option( 'highlights_infinite_enable' );
$highlights_fade  = magazine_bell_get_option( 'highlights_fade_enable' );
$header_font_size = magazine_bell_get_option( 'highlights_font_size');
$highlights_background_color = magazine_bell_get_option( 'highlights_background_color');
$highlights_post_count =magazine_bell_get_option( 'highlights_post_count_enable');
$excerpt_length =magazine_bell_get_option( 'highlights_excerpt_length');
$class ='';
if (true == $highlights_dot) {
   $class = 'true';
} else{
    $class = 'false';
}
for( $i=1; $i<=$number_of_highlights_items; $i++ ) :
    $highlights_page_posts[] = magazine_bell_get_option( 'highlights_page_'.$i );
    $highlights_posts[] = magazine_bell_get_option( 'highlights_post_'.$i );
endfor;
?>
<style>
    <?php if ($header_font_size != 0): ?>
        #highlights .entry-title{
            font-size:<?php echo esc_attr($header_font_size); ?>px;
        }
    <?php endif ?>
</style>
<?php if( !empty($highlights_title) ):?>
    <div class="section-header">
        <?php if (!empty($highlights_title)): ?>
            <h2 class="section-title"><?php echo esc_html($highlights_title);?></h2>
        <?php endif; ?>
    </div>       
<?php endif;?> 
<div class="highlights-wrapper" 
    data-slick='{"slidesToShow": <?php echo esc_attr( $highlights_column) ?>,
     "slidesToScroll": 1, 
     "infinite": <?php if( true== $highlights_infinite ){ echo 'true'; } else{ echo 'false'; } ?>, 
     "speed": <?php echo esc_attr( $highlights_speed) ?>, 
     "dots": <?php echo esc_html($class) ?>, 
     "arrows":<?php if( true== $highlights_arrow ){ echo 'true'; } else{ echo 'false'; } ?>, 
     "autoplay": <?php if( true== $highlights_autoplay ){ echo 'true'; } else{ echo 'false'; } ?>, 
     "fade": false }'>
        <?php
            $args = array (

            'posts_per_page' =>absint( $number_of_highlights_items ),              
            'post_type' => 'post',
            'post_status' => 'publish',
            'paged' => 1,
            );
            if ( absint( $highlights_category ) > 0 ) {
                $args['cat'] = absint( $highlights_category );
            }
        $loop = new WP_Query($args);                        
        if ( $loop->have_posts() ) :
        $i=0;  
            while ($loop->have_posts()) : $loop->the_post(); $i++;?>
                <article class="slick-item <?php echo has_post_thumbnail() ? 'has-post-thumbnail' : 'no-post-thumbnail' ; ?>" >
                    <?php if ($highlights_post_count==true && !has_post_thumbnail()): ?>
                        <span class="post-num"><?php echo $i; ?></span>
                    <?php endif ?>
                    <div class="highlights-items-wrapper">
                        <?php if (has_post_thumbnail()){ ?>
                            <div class="featured-image" style="background-image: url('<?php the_post_thumbnail_url( 'full');?>');">
                                <a href="<?php the_permalink();?>" class="post-thumbnail-link"></a> 
                                <?php if ($highlights_post_count==true ): ?>
                                    <span class="post-num"><?php echo $i; ?></span>
                                <?php endif ?>   
                            </div><!-- .featured-image -->
                        <?php } ?>
                        <div class="entry-container">
                            <?php if ( ($highlights_content_type != 'highlights_page') && ($enable_category==true)) { ?>
                                <div class="entry-meta">
                                    <?php magazine_bell_entry_meta(); ?>
                                </div><!-- .entry-meta -->
                            <?php } ?>
                            <header class="entry-header">
                                <h2 class="entry-title" ><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                            </header>
                            <?php if ( ($enable_content==true)): ?>
                                <div class="entry-content">
                                    <?php
                                        $excerpt = magazine_bell_the_excerpt( $excerpt_length );
                                        echo wp_kses_post( wpautop( $excerpt ) );
                                    ?>
                                </div><!-- .entry-content -->
                            <?php endif; ?>
                            
                            <?php if ( ($enable_posted_on==true)) { ?>
                                <div class="entry-meta">   
                                    <?php 
                                        if (($enable_posted_on==true)) {              
                                            magazine_bell_posted_on();
                                        } 
                                    ?>
                                </div><!-- .entry-meta -->
                            <?php } ?>

                        </div><!-- .entry-container --> 
                    </div>    
                </article><!-- .slick-item -->
            <?php endwhile;?>
        <?php endif;?>
        <?php wp_reset_postdata(); ?>
</div><!-- .highlights-wrapper -->
