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

get_header();
?>

<main id="primary">
    <?php 
    $plumbing_services_main_slider_wrap = absint(get_theme_mod('plumbing_services_enable_slider', 0));
    if($plumbing_services_main_slider_wrap == 1){ 
    ?>
    <div class="slider-bg">
       <section id="main-slider-wrap">
        <div class="owl-carousel">
            <?php for ($i=1; $i <= 3; $i++) { ?>
                <div class="main-slider-inner-box">
                    <?php if ( get_theme_mod('plumbing_services_slider_image'.$i) ) : ?>
                        <img src="<?php echo esc_url( get_theme_mod('plumbing_services_slider_image'.$i) ); ?>">
                        <div class="main-slider-content-box">
                            <?php if ( get_theme_mod('plumbing_services_slider_xtra_heading'.$i) ) : ?><h6><?php echo esc_html( get_theme_mod('plumbing_services_slider_xtra_heading'.$i) ); ?></h6><?php endif; ?>
                            <?php if ( get_theme_mod('plumbing_services_slider_heading'.$i) ) : ?><h3><?php echo esc_html( get_theme_mod('plumbing_services_slider_heading'.$i) ); ?></h3><?php endif; ?>
                            <?php if ( get_theme_mod('plumbing_services_slider_text'.$i) ) : ?><p><?php echo esc_html( get_theme_mod('plumbing_services_slider_text'.$i) ); ?></p><?php endif; ?>
                            <div class="main-slider-button">
                                <?php if ( get_theme_mod('plumbing_services_slider_button1_link'.$i) ||  get_theme_mod('plumbing_services_slider_button1_text'.$i )) : ?><a href="<?php echo esc_url( get_theme_mod('plumbing_services_slider_button1_link'.$i) ); ?>"><?php echo esc_html( get_theme_mod('plumbing_services_slider_button1_text'.$i) ); ?></a><?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            <?php } ?>
        </div>
    </section> 
    </div>
    <?php } ?>
     <?php 
    $plumbing_services_main_expert_wrap = absint(get_theme_mod('plumbing_services_enable_product_section', 0));
    if($plumbing_services_main_expert_wrap == 1){ 
    ?>
<section id="main-expert-wrap">
    <div class="container">
        <div class="feature-left">
            <?php if ( get_theme_mod('plumbing_services_product_section_heading') ) : ?><h3><?php echo esc_html( get_theme_mod('plumbing_services_product_section_heading') ); ?></h3><hr><?php endif; ?>
        </div>
        <div class="flex-row">
              <?php if ( class_exists( 'WooCommerce' ) ) {
                $args = array( 
                  'post_type' => 'product',
                  'product_cat' => get_theme_mod('plumbing_services_product_category'),
                  'order' => 'ASC',
                  'posts_per_page' => '10'
                );
                $loop = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>         
                    <div class="product-box">  
                          <div class="product-box-content">
                            <div class="product-image">
                                <?php 
                                    if ( has_post_thumbnail() ) {
                                        echo get_the_post_thumbnail( get_the_ID(), 'shop_catalog' );
                                    } else {
                                        echo '<img src="' . esc_url(wc_placeholder_img_src()) . '" alt="Placeholder" />';
                                    }
                                ?>
                            </div>
                            <div class="sale-tag">
                                <?php woocommerce_show_product_sale_flash( $product ); ?>
                            </div>
                            <h6 class="product-heading-text"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h6>
                            <div class="product-rating">
                                <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
                            </div>
                             <p class="product-price d-flex <?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></p>
                            <div class="cart-button align-items-center justify-content-center">
                              <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>  
                            </div>
                          </div>
                    </div> 
                <?php endwhile; wp_reset_postdata(); ?>
                <?php } ?>
            </div>
    </div>
</section>
<?php } ?>   
</main>
<?php
get_footer();