<?php
/**
 * The front page template file.
 *
 *
 * @package waves
 */
 
if ( 'posts' == get_option( 'show_on_front' ) ) { 
	    include( get_home_template() );
	} else {
	 get_template_part( 'slider-header' ); 
?>
 
<?php 
if ( get_theme_mod('page-builder' ) ) { ?>
		<div id="content" class="site-content">
		    <div class="container">
			<?php  if( get_theme_mod('home_sidebar',false ) ) { ?>
				<div id="primary" class="content-area eleven columns">
			<?php }else { ?>
			    <div id="primary" class="content-area sixteen columns">
			<?php } ?>  
				<main id="main" class="site-main" role="main">
					<?php
						while ( have_posts() ) : the_post();     
							the_content();
						endwhile;
					?>
					
			     </main><!-- #main -->
		     </div><!-- #primary -->
<?php	} else{ ?>
	<div id="content" class="site-content free-home">
		<div class="container">	
	<?php  if( get_theme_mod('home_sidebar',false ) ) { ?>
				<div id="primary" class="content-area eleven columns">
			<?php }else { ?>
			    <div id="primary" class="content-area sixteen columns">
			<?php } ?>
		<main id="main" class="site-main" role="main">
		    <div class="home-top"><?php 
				$service_top_page = get_theme_mod('service_top_page');
					// WP_Query arguments
				if ($service_top_page) {
					$args = array(
						'post_type' => 'page',
						'page_id' => $service_top_page,		
					);
						
					if( isset($args) ) :
					    // The Query
						$query = new WP_Query( $args );
						if( $query->have_posts()) : ?>
							<div class="services-top-wrapper row">
								<?php while($query->have_posts()) :
									$query->the_post(); ?>
									   	<h2 class="wave-title"> <span><?php the_title();?></span></h2>
									    <?php the_content(); ?>
								<?php endwhile; ?>
							</div>	
						<?php endif; 
						$query = null;
						$args = null;
						wp_reset_postdata();
					endif;
				}else{ ?>
					<div class="services-top-wrapper row">
					   <h2 class="wave-title"><span><?php _e('Service Top Wrapper','waves');?></span></h2>
					   <p><?php _e('You haven\'t created any service page yet. Create Page. Go to Customizer and click Waves Options => Home => Service Top Page and select page from  dropdown page list.','waves');?></p>
				   </div><?php 
				} 

			do_action('waves_service_content_before'); 

			if(get_theme_mod('enable_service',true) ) { 
			$service = get_theme_mod('service_count',4 );
				    $service_pages = array();
				    for ( $i = 1 ; $i <= $service ; $i++ ) {
						$service_page = absint(get_theme_mod('service_'.$i));
						if( $service_page ){
                            $service_pages[] = $service_page;
						}
				    }
			if( $service_pages && !empty( $service_pages ) ) {
				$args = array(
					'post_type' => 'page',
					'post__in' => $service_pages,
					'posts_per_page' => -1 ,
					'orderby' => 'post__in'
				);
			} 	else {?>
			<div class="services-wrapper row">
				 <div class="one-fourth service column">
				 	<span class="demo-thumb"><i class="fa fa-flag fa-5x"></i></span>
				 	<h4><?php _e('Service Section #1','waves');?></h4>
				 	<p><?php _e('You haven\'t created any service page yet. Create Page. Go to Customizer and click Waves Options => Home => Service Section #1 and select page from  dropdown page list.','waves');?></p>
				 </div>
				 <div class="one-fourth service column">
				 	<span class="demo-thumb">
				 		<i class="fa fa-random fa-5x"></i>	
				 	</span>
				 	<h4><?php _e('Service Section #2','waves');?></h4>
				 	<p><?php _e('You haven\'t created any service page yet. Create Page. Go to Customizer and click Waves Options => Home => Service Section #2 and select page from  dropdown page list.','waves');?></p>
				 </div>
				 <div class="one-fourth service column">
				 	<span class="demo-thumb">
				 		<i class="fa fa-mobile fa-5x"></i>	
				 	</span>
				 	<h4><?php _e('Service Section #3','waves');?></h4>
				 	<p><?php _e('You haven\'t created any service page yet. Create Page. Go to Customizer and click Waves Options => Home => Service Section #3 and select page from  dropdown page list.','waves');?></p>
				 </div>
				 <div class="one-fourth service column">
				 	<span class="demo-thumb">
				 		<i class="fa fa-thumb-tack fa-5x"></i>	
				 	</span>
				 	<h4><?php _e('Service Section #4','waves');?></h4>
				 	<p><?php _e('You haven\'t created any service page yet. Create Page. Go to Customizer and click Waves Options => Home => Service Section #4 and select page from  dropdown page list.','waves');?></p>
				 </div>
			</div>


		<?php	}

		if( isset($args) ) :
		$query = new WP_Query($args);
		if( $query->have_posts()) : ?>
			<div class="services-wrapper row">
		<?php while($query->have_posts()) :
				$query->the_post(); ?>
				    <div class="one-fourth service column">
				    	<?php if( has_post_thumbnail() ) : ?>
				    		<span>
				    		<a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_post_thumbnail('waves_recent_page_img'); ?></a>
				    		</span>
				    	<?php endif; ?>
				    	<h4><?php the_title(); ?></h4>   
				    	<?php the_content(); ?>
				    </div>
		<?php endwhile; ?>
			</div>
	      	
		<?php endif; ?>   
		<?php  
			$query = null;
			$args = null;
			wp_reset_postdata();
			endif;
		} ?>
		</div><?php
        do_action('waves_service_content_after');
		if( get_theme_mod('enable_recent_post_service',true)  ) {
			waves_recent_posts(); 
		} ?>	
		 	
	 <?php
	 if( get_theme_mod('enable_home_default_content',false ) ) {  ?>
			<div class="default-home-page"><?php
				while ( have_posts() ) : the_post();       
					the_content();
				endwhile; ?>
	         </div>    
      <?php } ?>
		</main><!-- #main -->
	</div><!-- #primary -->

<?php
}
if( get_theme_mod('home_sidebar',false ) ) { 
   get_sidebar();
}
get_footer();
} ?>
