<?php
/*
Template Name: Home Page
*/

get_header(); 
?>
<div class="content-area">
<?php
$shobe_show_cta = get_theme_mod( 'set_cta_show', 1 );
$shobe_button_url = get_theme_mod( 'set_cta_button_url');
$shobe_button_text = get_theme_mod( 'set_cta_button_text');
$args_cta = array(
    'post_type' => 'page',
    'post__in' => array(get_theme_mod( 'set_cta_page'))
);
$shobe_cta = get_posts($args_cta);

if( $shobe_show_cta == 1 ):
    if ( $shobe_cta ) : 
       
?>

   <div class="card intro-img position-relative" style="background-image: url(<?php echo esc_url(get_the_post_thumbnail_url( $shobe_cta[0]->ID, 'full'));?>);">
        <div class="container">
            <div class="captionsl">
                <h1 class="fw-medium"><?php echo $shobe_cta[0]->post_title;?></h1>
                <p class="fw-normal lh-base"><?php echo $shobe_cta[0]->post_content;?></p>
                <a href="<?php echo esc_url($shobe_button_url);?>" class="btn btn-dark"><?php echo esc_html($shobe_button_text);?></a>
            </div>
        </div>
       
    </div>
 <?php 
  
    else:
        if ( is_home() && current_user_can( 'publish_posts' ) ) :
			printf(
				'<div class="card intro-img position-relative"><div class="container"><p>' . wp_kses(
					/* translators: 1: link to WP admin new post page. */
					__( 'Ready to show the Call To Action Banner? <a href="%1$s">Get started here</a>.', 'shobe' ),
					array(
						'a' => array(
							'href' => array(),
						),
					)
				) . '</p></div></div>',
				esc_url( admin_url( 'customize.php' ) )
			);
        endif;
    endif; 
endif; 
?><!-- End showcta verification -->
   
<?php 
$shobe_show_services = get_theme_mod( 'set_service_show', 1 );
if( $shobe_show_services == 1 ): ?>

    <!-- START WHO WE ARE -->
    <section class="section">
        <div class="container">
            <div class="row">  
                <?php        
                for ($i=1; $i < 4; $i++) :
					// Getting data from Customizer to display the Service section
					$shobe_services[$i] 		= get_theme_mod( 'service_list_section_' . $i );
					$shobe_icon_service[$i]     = get_theme_mod( 'dropdown_select_icon_' . $i );
				endfor;
                $service_args = array(
					'post_type' 		=> 'page',
					'posts_per_page' 	=> 3,
					'post__in' 			=> $shobe_services,
					'orderby' 			=> 'post__in'
				);

				$service_loop = new WP_Query( $service_args );
				$j = 1;
                if( $service_loop->have_posts() ): 
					while( $service_loop->have_posts() ): 
						$service_loop->the_post();
				?>
                    <div class="col-lg-4 mt-4 pt-2">
                        <div class="about-box position-relative border rounded p-4">                        
                            <div class="abt-text position-relative">
                                <div class="fs-1 lh-base icon position-relative mb-5"><i class="<?php echo esc_attr( $shobe_icon_service[$j] )?>"></i></div>
                                <h4 class="mb-3"><?php the_title() ?></h4>
                                <p class="text-muted mb-0"><?php the_content();; ?></p>
                            </div>
                        </div>
                    </div>
				<?php
				    $j++;
				    endwhile;
				    wp_reset_postdata();
                    else :
                        if ( is_home() && current_user_can( 'publish_posts' ) ) :
                            printf(
                                '<div class="card intro-img position-relative"><div class="container"><p>' . wp_kses(
                                    /* translators: 1: link to WP admin new post page. */
                                    __( 'Want to add your service? <a href="%1$s">Get started here</a>.', 'shobe' ),
                                    array(
                                        'a' => array(
                                            'href' => array(),
                                        ),
                                    )
                                ) . '</p></div></div>',
                                esc_url( admin_url( 'customize.php' ) )
                            );
                        endif;
				endif; 
                ?>
                
            </div>
        </div>
    </section>
    <!-- END WHO WE ARE-->
<?php endif; ?>
<?php 
/*----------------------------------------------------------------------------------------------*/
// We'll only show these sections if WooCommerce is ative
if( class_exists( 'WooCommerce' ) ):
?>
    <!-- START TITLE -->
    <section  id="primary">
        <div class="container">
            <?php 
                // Getting data from Customizer to display the Popular Products section
                $shobe_popular_limit 		= get_theme_mod( 'set_popular_max_num', 4 );
                $shobe_show_popular = get_theme_mod( 'set_deal_show', 0 );
                $shobe_arrivals_limit 	= get_theme_mod( 'set_arrival_max_num', 4 );	
                $shobe_show_arrival = get_theme_mod( 'set_arrival_show', 0 );			

            ?>
            <?php if( $shobe_show_popular == 1 ): ?>
            <div class="section-title">
			    <h2 class="fs-24 fw-medium my-3 post-title"><?php echo esc_html( get_theme_mod( 'set_popular_title', __( 'Popular products', 'shobe' ) ) ); ?></h2>
			</div>
            <?php 
			    echo do_shortcode( '[products limit=" ' . esc_attr( $shobe_popular_limit ) . ' " columns="4" orderby="popularity" ]' );
			?>
            <?php endif; ?>
            <?php if( $shobe_show_arrival == 1 ): ?>
            <div class="section-title">
				<h2 class="fs-24 fw-medium my-3 post-title"><?php echo esc_html( get_theme_mod( 'set_arrival_title'), __( 'New Arrivals Products', 'shobe' )); ?></h2>
			</div>
			<?php 
			    echo do_shortcode( '[products limit=" ' . esc_attr( $shobe_arrivals_limit ) . ' " columns="4" orderby="date" visibility="visible" ]' ); 
			?>
            <?php endif; ?>		        
        </div>
    </section>
<?php endif; ?>
    <section>
        <div class="container">
        <?php 
        $set_news_show = get_theme_mod( 'set_news_show', 1 );			
        if( $set_news_show == 1 ): 
        ?>
            <div class="section-title">
				<h2 class="fs-24 fw-medium my-3 post-title"><?php echo esc_html( get_theme_mod( 'set_news_title'), __( 'Latest News', 'shobe' )); ?></h2>
			</div>
			<div class="row">
                <?php
				$args = array(
                    'post_type' 			=> 'post',
                    'posts_per_page' 		=> 3,
                    'ignore_sticky_posts' 	=> true,
                ); 	

				$blog_posts = new WP_Query( $args );

				if( $blog_posts->have_posts() ):
					while( $blog_posts->have_posts() ): $blog_posts->the_post();
					?>
                        <!-- Post-->
                        <article class="col-lg-4 post position-relative pb-5">
                            <div class="date-box rounded shadow text-center bg-white position-absolute top-0 start-0 p-2 ms-3 mt-3">
                                <h5 class="text-uppercase mb-0"><?php the_time( 'M j' );?></h5>
                            </div>
                            <div class="post-preview mb-4">      
                                <?php                      
                                if( has_post_thumbnail() ):
                                    the_post_thumbnail( 'shobe-blog' , array( 'class' => 'img-fluid rounded') );
                                endif;
                                ?>                     
                            </div>
                            <div class="post">
                                <h3 class="fs-20 fw-medium my-3 post-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3> 
                                    <p class="text-muted"><?php the_excerpt(); ?></p>
                                </div>  
                        </article>
                            <!-- Post end-->
					<?php
					endwhile;
					    wp_reset_postdata();
				else: 
					?>

                    <article id="post-0" class="post no-results not-found">

                        <?php
                        if ( current_user_can( 'edit_posts' ) ) :
                            // Show a different message to a logged-in user who can add posts.
                        ?>
                            <header class="entry-header">
                                <h1 class="entry-title"><?php _e( 'No posts to display', 'shobe' ); ?></h1>
                            </header>

                            <div class="entry-content">
                                <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'shobe' ), esc_url (admin_url( 'post-new.php' ) ) ); ?></p>
                            </div><!-- .entry-content -->
                        <?php
                        else :
                            // Show the default message to everyone else.
                        ?>
                            <header class="entry-header">
                                <h1 class="entry-title"><?php _e( 'Nothing Found', 'shobe' ); ?></h1>
                            </header>

                            <div class="entry-content pb-5">
                                <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'shobe' ); ?></p>
                                <?php get_search_form(); ?>
                            </div><!-- .entry-content -->
                        <?php endif; // end current_user_can() check ?>

                    </article><!-- #post-0 -->
                        
				   
			    <?php endif; ?>

            </div>
        <?php endif; ?>		
        </div>
    </section>
</div>   
<?php get_footer(); ?>
