<?php 
/**
 * Template part for displaying Featured Slider Section
 *
 *@package Spirit Business
 */

    $spirit_business_data_slick_speed                        = spirit_business_get_option( 'data_slick_speed' );
    $spirit_business_data_slick_arrows                       = spirit_business_get_option( 'data_slick_arrows' );
    $spirit_business_data_slick_dots                         = spirit_business_get_option( 'data_slick_dots' );
    $spirit_business_data_slick_fade                         = spirit_business_get_option( 'data_slick_fade' );
    $spirit_business_data_slick_infinite                     = spirit_business_get_option( 'data_slick_infinite' );
    $spirit_business_data_slick_autoplay                     = spirit_business_get_option( 'data_slick_autoplay' );
    $spirit_business_data_slick_draggable                    = spirit_business_get_option( 'data_slick_draggable' );
    $spirit_business_featured_slider_content_type            = spirit_business_get_option( 'featured_slider_content_type' );
    $spirit_business_number_of_featured_slider_items         = spirit_business_get_option( 'number_of_featured_slider_items' );
    $spirit_business_featured_slider_category                = spirit_business_get_option( 'featured_slider_category' );

    if( $spirit_business_featured_slider_content_type == 'featured_slider_page' ) :
        for( $i=1; $i<=$spirit_business_number_of_featured_slider_items; $i++ ) :
            $spirit_business_featured_slider_posts[] = spirit_business_get_option( 'featured_slider_page_'.$i );
        endfor;  
    elseif( $spirit_business_featured_slider_content_type == 'featured_slider_post' ) :
        for( $i=1; $i<=$spirit_business_number_of_featured_slider_items; $i++ ) :
            $spirit_business_featured_slider_posts[] = spirit_business_get_option( 'featured_slider_post_'.$i );
        endfor;
    endif;
    ?>

    <?php
        if( $spirit_business_data_slick_arrows == 0 ) {
            $spirit_business_data_slick_arrows = 'false';
        }
        else {
            $spirit_business_data_slick_arrows = 'true';
        }
    ?>

    <?php
        if( $spirit_business_data_slick_dots == 0 ) {
            $spirit_business_data_slick_dots = 'false';
        }
        else {
            $spirit_business_data_slick_dots = 'true';
        }
    ?>

    <?php
        if( $spirit_business_data_slick_fade == 0 ) {
            $spirit_business_data_slick_fade = 'false';
        }
        else {
            $spirit_business_data_slick_fade = 'true';
        }
    ?>

    <?php
        if( $spirit_business_data_slick_infinite == 0 ) {
            $spirit_business_data_slick_infinite = 'false';
        }
        else {
            $spirit_business_data_slick_infinite = 'true';
        }
    ?>

    <?php
        if( $spirit_business_data_slick_autoplay == 0 ) {
            $spirit_business_data_slick_autoplay = 'false';
        }
        else {
            $spirit_business_data_slick_autoplay = 'true';
        }
    ?>

    <?php
        if( $spirit_business_data_slick_draggable == 0 ) {
            $spirit_business_data_slick_draggable = 'false';
        }
        else {
            $spirit_business_data_slick_draggable = 'true';
        }
    ?>

    <?php if( $spirit_business_featured_slider_content_type == 'featured_slider_page' ) : ?>
        <section id="featured-slider">
            <div class="section-content" data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": <?php echo esc_attr( $spirit_business_data_slick_infinite ); ?>, "speed": <?php echo esc_attr( $spirit_business_data_slick_speed ); ?>, "dots": <?php echo esc_attr( $spirit_business_data_slick_dots ); ?>, "arrows": <?php echo esc_attr( $spirit_business_data_slick_arrows ); ?>, "autoplay": <?php echo esc_attr( $spirit_business_data_slick_autoplay ); ?>, "draggable": <?php echo esc_attr( $spirit_business_data_slick_draggable ); ?>, "fade": <?php echo esc_attr( $spirit_business_data_slick_fade ); ?> }'>
                <?php $args = array (
                    'post_type'     => 'page',
                    'posts_per_page' => absint( $spirit_business_number_of_featured_slider_items ),
                    'post__in'      => $spirit_business_featured_slider_posts,
                    'orderby'       =>'post__in',
                );        
                $spirit_business_loop = new WP_Query($args);                        
                if ( $spirit_business_loop->have_posts() ) :
                $i=-1; $j=0; 
                    while ($spirit_business_loop->have_posts()) : $spirit_business_loop->the_post(); $i++; $j++;
                    $spirit_business_featured_slider_subtitle[$j] = spirit_business_get_option( 'featured_slider_subtitle_'.$j );
                    $spirit_business_featured_slider_btn_text_one[$j] = spirit_business_get_option( 'featured_slider_btn_text_one_'.$j );
                    $spirit_business_featured_slider_btn_text_two[$j] = spirit_business_get_option( 'featured_slider_btn_text_two_'.$j );
                    $spirit_business_featured_slider_btn_url_one[$j] = spirit_business_get_option( 'featured_slider_btn_url_one_'.$j );
                    $spirit_business_featured_slider_btn_url_two[$j] = spirit_business_get_option( 'featured_slider_btn_url_two_'.$j );

                    $spirit_business_class='';
                    if ($i==0) {
                        $spirit_business_class='display-block';
                    } else{
                        $spirit_business_class='display-none';}
                    ?>              
                    
                    <article class="<?php echo esc_attr($spirit_business_class); ?>" style="background-image: url('<?php the_post_thumbnail_url( 'full' ); ?>');">
                        <div class="overlay"></div>
                        <div class="wrapper">
                            <div class="featured-content-wrapper">
                                <header class="entry-header">
                                    <?php if( !empty($spirit_business_featured_slider_subtitle[$j]) ):?>
                                        <h3 class="entry-subtitle"><?php echo esc_html($spirit_business_featured_slider_subtitle[$j]);?></h3>
                                    <?php endif;?>
                                    <h2 class="entry-title"><?php the_title();?></h2>
                                </header>

                                <div class="entry-content">
                                    <?php
                                        $spirit_business_excerpt = spirit_business_the_excerpt( 25 );
                                        echo wp_kses_post( wpautop( $spirit_business_excerpt ) );
                                    ?>
                                </div><!-- .entry-content -->

                                <div class="read-more">
                                    <?php if( !empty($spirit_business_featured_slider_btn_text_one[$j]) ):?>
                                        <a href="<?php the_permalink();?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_one[$j]);?></a>
                                    <?php endif;?>

                                    <?php if( !empty($spirit_business_featured_slider_btn_text_two[$j]) ):?>
                                        <a href="<?php echo esc_attr($spirit_business_featured_slider_btn_url_two[$j]);?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_two[$j]);?></a>
                                    <?php endif;?>
                                </div><!-- .read-more -->
                            </div><!-- .featured-content-wrapper -->
                        </div><!-- .wrapper -->
                    </article>

                    <?php endwhile; ?>
                <?php endif; ?>
                <?php wp_reset_postdata(); ?>
            </div><!-- .section-content -->
        </section>
    
    <?php elseif( $spirit_business_featured_slider_content_type == 'featured_slider_post' ) : ?>
        <section id="featured-slider">
            <div class="section-content" data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": <?php echo esc_attr( $spirit_business_data_slick_infinite ); ?>, "speed": <?php echo esc_attr( $spirit_business_data_slick_speed ); ?>, "dots": <?php echo esc_attr( $spirit_business_data_slick_dots ); ?>, "arrows": <?php echo esc_attr( $spirit_business_data_slick_arrows ); ?>, "autoplay": <?php echo esc_attr( $spirit_business_data_slick_autoplay ); ?>, "draggable": <?php echo esc_attr( $spirit_business_data_slick_draggable ); ?>, "fade": <?php echo esc_attr( $spirit_business_data_slick_fade ); ?> }'>
                <?php $args = array (
                    'post_type'     => 'post',
                    'posts_per_page' => absint( $spirit_business_number_of_featured_slider_items ),
                    'post__in'      => $spirit_business_featured_slider_posts,
                    'orderby'       =>'post__in',
                    'ignore_sticky_posts' => true,
                );        
                $spirit_business_loop = new WP_Query($args);                        
                if ( $spirit_business_loop->have_posts() ) :
                $i=-1; $j=0; 
                    while ($spirit_business_loop->have_posts()) : $spirit_business_loop->the_post(); $i++; $j++;
                    $spirit_business_featured_slider_subtitle[$j] = spirit_business_get_option( 'featured_slider_subtitle_'.$j );
                    $spirit_business_featured_slider_btn_text_one[$j] = spirit_business_get_option( 'featured_slider_btn_text_one_'.$j );
                    $spirit_business_featured_slider_btn_text_two[$j] = spirit_business_get_option( 'featured_slider_btn_text_two_'.$j );
                    $spirit_business_featured_slider_btn_url_one[$j] = spirit_business_get_option( 'featured_slider_btn_url_one_'.$j );
                    $spirit_business_featured_slider_btn_url_two[$j] = spirit_business_get_option( 'featured_slider_btn_url_two_'.$j );

                    $spirit_business_class='';
                    if ($i==0) {
                        $spirit_business_class='display-block';
                    } else{
                        $spirit_business_class='display-none';}
                    ?>            
                    
                    <article class="<?php echo esc_attr($spirit_business_class); ?>" style="background-image: url('<?php the_post_thumbnail_url( 'full' ); ?>');">
                        <div class="overlay"></div>
                        <div class="wrapper">
                            <div class="featured-content-wrapper">
                                <header class="entry-header">
                                    <?php if( !empty($spirit_business_featured_slider_subtitle[$j]) ):?>
                                        <h3 class="entry-subtitle"><?php echo esc_html($spirit_business_featured_slider_subtitle[$j]);?></h3>
                                    <?php endif;?>
                                    <h2 class="entry-title"><?php the_title();?></h2>
                                </header>

                                <div class="entry-content">
                                    <?php
                                        $spirit_business_excerpt = spirit_business_the_excerpt( 25 );
                                        echo wp_kses_post( wpautop( $spirit_business_excerpt ) );
                                    ?>
                                </div><!-- .entry-content -->

                                <div class="read-more">
                                    <?php if( !empty($spirit_business_featured_slider_btn_text_one[$j]) ):?>
                                        <a href="<?php the_permalink();?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_one[$j]);?></a>
                                    <?php endif;?>

                                    <?php if( !empty($spirit_business_featured_slider_btn_text_two[$j]) ):?>
                                        <a href="<?php echo esc_attr($spirit_business_featured_slider_btn_url_two[$j]);?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_two[$j]);?></a>
                                    <?php endif;?>
                                </div><!-- .read-more -->
                            </div><!-- .featured-content-wrapper -->
                        </div><!-- .wrapper -->
                    </article>

                    <?php endwhile; ?>
                <?php endif; ?>
                <?php wp_reset_postdata(); ?>
            </div><!-- .section-content -->
        </section>

    <?php else: ?>
        <section id="featured-slider">
            <div class="section-content" data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": <?php echo esc_attr( $spirit_business_data_slick_infinite ); ?>, "speed": <?php echo esc_attr( $spirit_business_data_slick_speed ); ?>, "dots": <?php echo esc_attr( $spirit_business_data_slick_dots ); ?>, "arrows": <?php echo esc_attr( $spirit_business_data_slick_arrows ); ?>, "autoplay": <?php echo esc_attr( $spirit_business_data_slick_autoplay ); ?>, "draggable": <?php echo esc_attr( $spirit_business_data_slick_draggable ); ?>, "fade": <?php echo esc_attr( $spirit_business_data_slick_fade ); ?> }'>
                <?php $args = array (
                    'posts_per_page' =>absint( $spirit_business_number_of_featured_slider_items ),
                       'post_type' => 'post',
                       'post_status' => 'publish',
                       'paged' => 1,
                        'ignore_sticky_posts' => true,
                       );
                       if ( absint( $spirit_business_featured_slider_category ) > 0 ) {
                           $args['cat'] = absint( $spirit_business_featured_slider_category );
                       }      
                $spirit_business_loop = new WP_Query($args);                        
                if ( $spirit_business_loop->have_posts() ) :
                $i=-1; $j=0;
                    while ($spirit_business_loop->have_posts()) : $spirit_business_loop->the_post(); $i++; $j++;
                    $spirit_business_featured_slider_subtitle[$j] = spirit_business_get_option( 'featured_slider_subtitle_'.$j );
                    $spirit_business_featured_slider_btn_text_one[$j] = spirit_business_get_option( 'featured_slider_btn_text_one_'.$j );
                    $spirit_business_featured_slider_btn_text_two[$j] = spirit_business_get_option( 'featured_slider_btn_text_two_'.$j );
                    $spirit_business_featured_slider_btn_url_one[$j] = spirit_business_get_option( 'featured_slider_btn_url_one_'.$j );
                    $spirit_business_featured_slider_btn_url_two[$j] = spirit_business_get_option( 'featured_slider_btn_url_two_'.$j );

                    $spirit_business_class='';
                    if ($i==0) {
                        $spirit_business_class='display-block';
                    } else{
                        $spirit_business_class='display-none';}
                    ?>                
                    
                    <article class="<?php echo esc_attr($spirit_business_class); ?>" style="background-image: url('<?php the_post_thumbnail_url( 'full' ); ?>');">
                        <div class="overlay"></div>
                        <div class="wrapper">
                            <div class="featured-content-wrapper">
                                <header class="entry-header">
                                    <?php if( !empty($spirit_business_featured_slider_subtitle[$j]) ):?>
                                        <h3 class="entry-subtitle"><?php echo esc_html($spirit_business_featured_slider_subtitle[$j]);?></h3>
                                    <?php endif;?>
                                    <h2 class="entry-title"><?php the_title();?></h2>
                                </header>

                                <div class="entry-content">
                                    <?php
                                        $spirit_business_excerpt = spirit_business_the_excerpt( 25 );
                                        echo wp_kses_post( wpautop( $spirit_business_excerpt ) );
                                    ?>
                                </div><!-- .entry-content -->

                                <div class="read-more">
                                    <?php if( !empty($spirit_business_featured_slider_btn_text_one[$j]) ):?>
                                        <a href="<?php the_permalink();?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_one[$j]);?></a>
                                    <?php endif;?>

                                    <?php if( !empty($spirit_business_featured_slider_btn_text_two[$j]) ):?>
                                        <a href="<?php echo esc_attr($spirit_business_featured_slider_btn_url_two[$j]);?>" class="btn"><?php echo esc_html($spirit_business_featured_slider_btn_text_two[$j]);?></a>
                                    <?php endif;?>
                                </div><!-- .read-more -->
                            </div><!-- .featured-content-wrapper -->
                        </div><!-- .wrapper -->
                    </article>

                    <?php endwhile; ?>
                <?php endif; ?>
                <?php wp_reset_postdata(); ?>
            </div><!-- .section-content -->
        </section>
    <?php endif;