<?php
/**
 * Banner Section
 * 
 * @package Wellness_Coach_Lite
 */

$ed_banner         = get_theme_mod( 'ed_banner_section', 'static_banner' );
$slider_type       = get_theme_mod( 'slider_type', 'latest_posts' ); 
$slider_cat        = get_theme_mod( 'slider_cat' );
$posts_per_page    = get_theme_mod( 'no_of_slides', 4 );
$ed_full_image     = get_theme_mod( 'slider_full_image', false );
$ed_caption        = get_theme_mod( 'slider_caption', true );
$read_more         = get_theme_mod( 'slider_readmore', __( 'Learn More', 'wellness-coach-lite' ) );
$banner_title      = get_theme_mod( 'banner_title' );
$banner_subtitle   = get_theme_mod( 'banner_subtitle' ); 
$banner_content    = get_theme_mod( 'banner_content' );
$button_one        = get_theme_mod( 'button_one' );
$button_one_url    = get_theme_mod( 'button_one_url' );
$button_two        = get_theme_mod( 'button_two' );
$button_two_url    = get_theme_mod( 'button_two_url' );
$button_one_new    = get_theme_mod( 'button_one_tab_new', false );
$button_two_new    = get_theme_mod( 'button_two_tab_new', false );
$banner_newsletter = get_theme_mod( 'banner_newsletter' );
$newsletter_layout = get_theme_mod( 'newsletter_banner_layout', 'two' );
$cta_layout        = get_theme_mod( 'cta_static_banner_layout', 'one' );
$slider_layout     = get_theme_mod( 'slider_layout', 'one' );
$banner_caption_layout    = get_theme_mod( 'banner_caption_layout', 'left' );
$target_one = $target_two = '';
$image_size = $ed_full_image ? 'full' : 'wellness-coach-lite-slider';

if( ( $ed_banner == 'static_banner' || $ed_banner == 'static_nl_banner' ) && has_custom_header() ){ ?>
    <section class="site-banner<?php if( $ed_banner == 'static_nl_banner' ) echo ' cta-newsletter-banner style-' . esc_attr( $newsletter_layout ); ?><?php if( $ed_banner == 'static_banner' ) echo ' static-cta'; ?><?php if( $ed_banner == 'static_banner' ) echo ' style-' . esc_attr( $cta_layout ); ?><?php if( $ed_banner == 'static_ap_banner' ) echo ' appointment-banner style-' . esc_attr( $newsletter_layout ); ?><?php if( has_header_video() ) echo esc_attr( ' video-banner' ); ?>">
        <div id="banner_section" class="banner-wrapper">
            <div class="item <?php echo esc_attr( $banner_caption_layout ); ?>">
                <?php 
                    the_custom_header_markup();
                    if( ! has_header_video() ){
                        if( $ed_banner == 'static_banner' && ( $banner_title || $banner_subtitle || $banner_content || ( ( $button_one && $button_one_url ) || ( $button_two && $button_two_url ) ) ) ){
                            echo '<div class="caption-wrapper"><div class="container"><div class="banner-caption">';
                            if( $banner_subtitle ) echo '<h5 class="subtitle">' . esc_html( $banner_subtitle ) . '</h5>';
                            if( $banner_title ) echo '<h2 class="banner-title">' . esc_html( $banner_title ) . '</h2>';
                            if( $banner_content ) echo '<div class="banner-desc">' . wp_kses_post( wpautop( $banner_content ) ) . '</div>';
                            if( ( $button_one && $button_one_url ) || ( $button_two && $button_two_url ) ) {
                                echo '<div class="banner-button-wrap">';
                                if( $button_one && $button_one_url ) {
                                    if( $button_one_new ) $target_one = ' target="_blank"';
                                    echo '<a href="' . esc_url( $button_one_url ) . '" class="wc-btn wc-btn-one"' . $target_one . '>' . esc_html( $button_one ) . '</a>';                              
                                }
                                if( $button_two && $button_two_url ) {
                                    if( $button_two_new ) $target_two = ' target="_blank"';
                                    echo '<a href="' . esc_url( $button_two_url  ) . '" class="wc-btn wc-btn-two"' . $target_two . '>' . esc_html( $button_two ) . '</a>';
                                }                      
                                echo '</div>';
                            }
                            echo '</div></div></div>';
                        }elseif( $ed_banner == 'static_nl_banner' && $banner_newsletter ){
                            echo '<div class="caption-wrapper"><div class="container"><div class="banner-caption">';
                            echo '<section class="widget widget_blossomthemes_email_newsletter_widget">';
                            echo do_shortcode( wp_kses_post( $banner_newsletter ) );
                            echo '</section>';
                            echo '</div></div></div>';
                        }   
                    }
                ?>
            </div>
        </div>
    </section>
<?php
}elseif( $ed_banner == 'slider_banner' ){
    if( $slider_type == 'latest_posts' || $slider_type == 'cat' || $slider_type == 'pages' ){
        
        $args = array(
            'post_status'         => 'publish',            
            'ignore_sticky_posts' => true
        );
        
        if( $slider_type === 'cat' && $slider_cat ){
            $args['post_type']      = 'post';
            $args['cat']            = $slider_cat; 
            $args['posts_per_page'] = -1;  
        }else{
            $args['post_type']      = 'post';
            $args['posts_per_page'] = $posts_per_page;
        }
            
        $qry = new WP_Query( $args );
        
        if( $qry->have_posts() ){ ?>
            <section class="site-banner slider-<?php echo esc_html( $slider_layout ); ?>">
                <?php echo '<div class="container">'; ?>                
                    <div class="banner-wrapper owl-carousel">            
            			<?php while( $qry->have_posts() ){ $qry->the_post(); ?>
                        <div class="item <?php echo esc_attr( $image_size ); ?>">
                            <div class="banner-img-wrap">
                				<?php 
                                if( has_post_thumbnail() ){
                				    the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );    
                				}else{ 
                				    wellness_coach_lite_get_fallback_svg( 'wellness-coach-lite-slider' );//fallback
                                } ?>
                            </div>
                            <?php if( $ed_caption ){ ?>                        
                				<div class="banner-caption">
        							<?php
                                        the_title( '<h2 class="banner-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
                                        echo '<div class="banner-desc">';
                                        the_excerpt();
                                        echo '</div>';

                                        if( $read_more ) {
                                            echo '<div class="banner-button-wrap">';
                                            echo '<a href="' . esc_url( get_the_permalink() ) . '" class="wc-btn wc-btn-two">' . esc_html( $read_more ) . '</a>';
                                            echo '</div>';
                                        }                            
                                    ?>
                				</div>
                            <?php } ?>
            			</div>
            			<?php } ?>                        
        		<?php echo '</div>'; ?>                
    	   </div>
        </section>
        <?php
        wp_reset_postdata();
        }
    
    }
}