<?php
global $demo_slides;

if ( get_theme_mod( 'oceanic-slider-type', false ) == 'oceanic-no-slider' ) {
?>
	<!-- No Slider -->
<?php
} else if ( get_theme_mod( 'oceanic-slider-type', false ) == 'oceanic-meta-slider' ) {
    
    $slider_code = '';
    if ( get_theme_mod( 'oceanic-meta-slider-shortcode', false ) ) {
        $slider_code = get_theme_mod( 'oceanic-meta-slider-shortcode' );
    }
    
    echo do_shortcode( sanitize_text_field( $slider_code ) );
    
} else {
    
	$slider_categories = get_theme_mod( 'oceanic-slider-cats', customizer_library_get_default( 'oceanic-slider-cats' ) );
	
	if ( !is_array($slider_categories) ) {
		$slider_categories = array();
	}
    
    if ( $slider_categories ) {
        
			$slider_query = new WP_Query( 'cat=' . implode(',', $slider_categories) . '&posts_per_page=-1&orderby=date&order=DESC&id=slider' );
	        
	        if ( $slider_query->have_posts() ) {
	        ?>
	
				<div class="home-slider-wrap home-slider-remove">
					<div class="home-slider-prev">
						<i class="fa fa-angle-left"></i>
					</div>
					<div class="home-slider-next">
						<i class="fa fa-angle-right"></i>
					</div>
				
					<div class="home-slider">

						<?php
						$slide_i = 0;

						while ( $slider_query->have_posts() ) : $slider_query->the_post();
							$is_first = ( 0 === $slide_i );

							$thumb_attrs = array(
								'decoding'      => 'async',
								'loading'       => $is_first ? 'eager' : 'lazy',
								'fetchpriority' => $is_first ? 'high' : 'low',
								'sizes'         => '100vw',
							);
						?>
				                
						<div>
							<?php
							if ( has_post_thumbnail() ) {
								the_post_thumbnail( 'full', $thumb_attrs );
							}
							?>
				                            
							<div class="overlay"><?php the_content(); ?></div>
						</div>
          
						<?php
							$slide_i++;
						endwhile;
						?>

					</div>
					
					<div class="home-slider-pager"></div>
					
				</div>
	
		<?php
			}
			wp_reset_query();
	
    } else {
   	?>
        
        <div class="home-slider-wrap home-slider-remove">
            <div class="home-slider-prev"><i class="fa fa-angle-left"></i></div>
            <div class="home-slider-next"><i class="fa fa-angle-right"></i></div>
                
            <div class="home-slider">
				<?php
				$slide_i = 0;
				foreach ( $demo_slides as $slide ) {
					$is_first = ( 0 === $slide_i );
				?>

				<div>
					<img
						src="<?php echo esc_url( $slide['image'] ); ?>"
						alt="<?php echo esc_attr__( 'Demo Slide', 'oceanic' ); ?>"
						decoding="async"
						loading="<?php echo $is_first ? 'eager' : 'lazy'; ?>"
						fetchpriority="<?php echo $is_first ? 'high' : 'low'; ?>"
						width="1920"
						height="905"
					/>				
                    <div class="overlay">
						<?php
						echo ( trim( $slide['text'] ) );
						?>
					</div>
				</div>
				<?php
					$slide_i++;
	            }
				?>				
                
            </div>
            <div class="home-slider-pager"></div>
        </div>

    <?php
    }

}
