<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Classic Beauty Parlour
 */

get_header(); ?>

<div id="content" >

    <?php
        $classic_beauty_parlour_hidepageboxes = get_theme_mod('classic_beauty_parlour_slider', true);
        $classic_beauty_parlour_catData = get_theme_mod('classic_beauty_parlour_slider_cat');
        if ($classic_beauty_parlour_hidepageboxes && $classic_beauty_parlour_catData) { ?>
        <section id="slider-cat" class="wow bounceInDown" data-wow-duration="2s">
            <div class="container">
                <div class="owl-carousel m-0">
                    <?php
                        $classic_beauty_parlour_page_query = new WP_Query(
                            array(
                                'category_name' => esc_attr($classic_beauty_parlour_catData),
                                'posts_per_page' => 3,
                            )
                        );
                        while ($classic_beauty_parlour_page_query->have_posts()) : $classic_beauty_parlour_page_query->the_post(); ?>
                            <div class="slider-content">
                                <div class="row">
                                    <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-12 align-self-center slider-detail">
                                        <div class="text-content">
                                            <?php if (get_theme_mod('classic_beauty_parlour_slider_sub_title') != "") { ?>
                                                <p class="slider-subtitle text-capitalize"><?php echo esc_html(get_theme_mod('classic_beauty_parlour_slider_sub_title')); ?></p>
                                            <?php } ?>
                                            <h1 class="slider-title text-capitalize mb-4"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                            <div class="sliderbtn pt-3">
                                                <?php 
                                                    $classic_beauty_parlour_button_text = get_theme_mod('classic_beauty_parlour_button_text', 'Browse More');
                                                    $classic_beauty_parlour_button_link_slider = get_theme_mod('classic_beauty_parlour_button_link_slider', ''); 
                                                    if (empty($classic_beauty_parlour_button_link_slider)) {
                                                        $classic_beauty_parlour_button_link_slider = esc_url(get_permalink());
                                                    }
                                                    if ($classic_beauty_parlour_button_text || !empty($classic_beauty_parlour_button_link_slider)) { ?>
                                                    <?php if(get_theme_mod('classic_beauty_parlour_button_text', 'Browse More') != ''){ ?>
                                                        <a href="<?php echo esc_url($classic_beauty_parlour_button_link_slider); ?>" class="post-btn text-uppercase">
                                                            <?php echo esc_html($classic_beauty_parlour_button_text); ?>
                                                            <span class="screen-reader-text"><?php echo esc_html($classic_beauty_parlour_button_text); ?></span>
                                                        </a>
                                                    <?php } ?>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-12 align-self-center imagebox">
                                        <?php if(has_post_thumbnail()){
                                            the_post_thumbnail('full', array('class' => 'post-image'));
                                        } else { ?>
                                            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/post-img.png" alt="<?php echo esc_attr( 'post-img', 'classic-beauty-parlour'); ?>" class="post-image"/>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile;
                        wp_reset_postdata();
                    ?>
                </div>
                <div class="banner-bottom">
                    <?php if (get_theme_mod('classic_beauty_parlour_banner_bottom_img')) { ?>
                        <img src="<?php echo esc_url(get_theme_mod('classic_beauty_parlour_banner_bottom_img')); ?>" alt="<?php echo esc_attr( 'banner', 'classic-beauty-parlour'); ?>"/> 
                    <?php } else { ?>
                        <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/bottom-img.png" alt="<?php echo esc_attr( 'banner', 'classic-beauty-parlour'); ?>"/>
                    <?php } ?>
                </div>
            </div>
        </section>
    <?php } ?>

    <!-- Trending Products Section -->
    <?php 
        $classic_beauty_parlour_hide_trending_section = get_theme_mod('classic_beauty_parlour_disabled_trending_section', true);
        if ($classic_beauty_parlour_hide_trending_section){ ?>
        <section id="trending-section" class="py-5">
            <div class="container">
                <div class="blog-bx mb-2 text-center">
                    <?php if (get_theme_mod('classic_beauty_parlour_trending_title') != "") { ?>
                        <h2 class="trending-title pb-3 text-capitalize"><?php echo esc_html(get_theme_mod('classic_beauty_parlour_trending_title')); ?></h2>
                    <?php } ?>
                </div>
                <div class="row">
                    <?php if (class_exists('woocommerce')) {
                        $classic_beauty_parlour_selected_category = get_theme_mod('classic_beauty_parlour_hot_products_cat');
                        
                        if ($classic_beauty_parlour_selected_category && $classic_beauty_parlour_selected_category !== 'select') {
                            $classic_beauty_parlour_args = array(
                                'post_type' => 'product',
                                'product_cat' => $classic_beauty_parlour_selected_category,
                                'order' => 'ASC',
                                'posts_per_page' => 4,
                            );
                            $classic_beauty_parlour_loop = new WP_Query($classic_beauty_parlour_args);
                            if ($classic_beauty_parlour_loop->have_posts()) {
                                while ($classic_beauty_parlour_loop->have_posts()) : $classic_beauty_parlour_loop->the_post(); 
                                    global $product;
                                    $classic_beauty_parlour_product_categories = wp_get_post_terms($product->get_id(), 'product_cat');
                                    if (!empty($classic_beauty_parlour_product_categories) && !is_wp_error($classic_beauty_parlour_product_categories)) {
                                        $classic_beauty_parlour_product_category = $classic_beauty_parlour_product_categories[0];
                                    }
                                    $classic_beauty_parlour_regular_price = $product->get_regular_price();
                                    $classic_beauty_parlour_sale_price = $product->get_sale_price();
                                    $classic_beauty_parlour_percentage_discount = 0;

                                    if ($classic_beauty_parlour_regular_price && $classic_beauty_parlour_sale_price) {
                                        $classic_beauty_parlour_percentage_discount = -1 * round( ( ($classic_beauty_parlour_regular_price - $classic_beauty_parlour_sale_price) / $classic_beauty_parlour_regular_price ) * 100 ); 
                                    }
                                ?>
                                <div class="col-xl-3 col-lg-3 col-md-6 col-sm-6 col-12 mb-3">
                                    <div class="product-content wow zoomIn" data-wow-duration="2s">
                                        <div class="product-image position-relative">
                                            <?php
                                            if (has_post_thumbnail($classic_beauty_parlour_loop->post->ID)) {
                                                the_post_thumbnail($classic_beauty_parlour_loop->post->ID, 'shop_catalog');
                                            } else {
                                                echo '<img src="' . esc_url(wc_placeholder_img_src()) . '" alt="' . esc_attr__('product-image', 'classic-beauty-parlour') . '" />';
                                            }
                                            ?>
                                            <?php if($classic_beauty_parlour_percentage_discount != 0) { ?>
                                                <div class="discount-badge"><?php echo $classic_beauty_parlour_percentage_discount; ?>%</div>
                                            <?php } ?>
                                            <div class="addcart">
                                                <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $classic_beauty_parlour_loop->post, $product ); } ?>
                                            </div>
                                            <?php if (shortcode_exists('woosw')) { ?>
                                                <div class="wishlist-main">
                                                    <?php echo do_shortcode('[woosw]'); ?>
                                                </div>
                                            <?php } ?>
                                        </div>
                                        <div class="product-detail text-center">
                                            <h3 class="my-2 text-capitalize product-heading">
                                                <a href="<?php echo esc_url(get_permalink($classic_beauty_parlour_loop->post->ID)); ?>">
                                                    <?php the_title(); ?>
                                                </a>
                                            </h3>
                                            <?php if( $product->is_type( 'simple' ) ){ ?>
                                                <div class="rating">
                                                    <?php woocommerce_template_loop_rating( $classic_beauty_parlour_loop->post, $product ); ?>
                                                </div>
                                            <?php } ?>
                                            <div class="price my-2">
                                                <?php echo $product->get_price_html(); ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php endwhile; 
                                wp_reset_postdata();
                            }
                        }
                    } ?>
                </div>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>
