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

get_header();
?>

<main id="primary">

    <?php if (get_theme_mod('fashion_outfits_trend_banner_section_on_off_setting', false)) { ?>
        <section id="main-banner-wrap">
            <div class="container">
                <div class="row">
                    <div class="col-lg-5 col-md-5">
                        <div class="main-banner-content-box">
                            <?php
                                $fashion_outfits_trend_discount_text = get_theme_mod( 'fashion_outfits_trend_discount_text', 'Flat 50% Off' );
                                if ( ! empty( $fashion_outfits_trend_discount_text ) ) { ?>
                                <h4><?php echo esc_html( $fashion_outfits_trend_discount_text ); ?></h4>
                            <?php } ?>
                            <?php
                                $fashion_outfits_trend_banner_heading = get_theme_mod( 'fashion_outfits_trend_banner_heading', 'Fashion That Boosts Your Confidence' );
                                if ( ! empty( $fashion_outfits_trend_banner_heading ) ) { ?>
                                <h3 id="myHeading" class="myHeading"><?php echo esc_html( $fashion_outfits_trend_banner_heading ); ?></h3>
                            <?php } ?>
                            <?php
                                $fashion_outfits_trend_banner_content = get_theme_mod( 'fashion_outfits_trend_banner_content', 'Munere vocibus pro no. Eu meis exerci deserunt vel, est ignota dolorum consetetur id. Officiis eleifend pat' );
                                if ( ! empty( $fashion_outfits_trend_banner_content ) ) { ?>
                                <p><?php echo esc_html( $fashion_outfits_trend_banner_content ); ?></p>
                            <?php } ?>
                            <?php
                                $fashion_outfits_trend_banner_btn = get_theme_mod( 'fashion_outfits_trend_banner_btn', 'Shop Now' );
                                $fashion_outfits_trend_banner_button_link = get_theme_mod( 'fashion_outfits_trend_banner_button_link', '#' );
                                if ( ! empty( $fashion_outfits_trend_banner_btn ) ) { ?>
                                <a href="<?php echo esc_url( $fashion_outfits_trend_banner_button_link ); ?>"><?php echo esc_html( $fashion_outfits_trend_banner_btn ); ?></a>
                            <?php } ?>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4">
                        <div class="main-banner-inner-box">
                            <?php
                            $fashion_outfits_trend_banner_image = get_theme_mod( 'fashion_outfits_trend_banner_image', '' );
                            if ( ! empty( $fashion_outfits_trend_banner_image ) ) { ?>
                                <img src="<?php echo esc_url( $fashion_outfits_trend_banner_image ); ?>">
                            <?php } ?>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3">
                        <div class="big-sale-box">
                            <?php
                                $fashion_outfits_trend_sale_image = get_theme_mod( 'fashion_outfits_trend_sale_image', '' );
                                if ( ! empty( $fashion_outfits_trend_sale_image ) ) { ?>
                                    <img src="<?php echo esc_url( $fashion_outfits_trend_sale_image ); ?>">
                            <?php } ?>
                            <div class="big-sale-text">
                                <?php
                                    $fashion_outfits_trend_sale_heading = get_theme_mod( 'fashion_outfits_trend_sale_heading', 'BIG SALE' );
                                    if ( ! empty( $fashion_outfits_trend_sale_heading ) ) { ?>
                                    <h3 class="mb-0"><?php echo esc_html( $fashion_outfits_trend_sale_heading ); ?></h3>
                                <?php } ?>
                                <?php
                                    $fashion_outfits_trend_sale_text = get_theme_mod( 'fashion_outfits_trend_sale_text', 'Pick the best Fashion' );
                                    if ( ! empty( $fashion_outfits_trend_sale_text ) ) { ?>
                                    <p class="mb-0"><?php echo esc_html( $fashion_outfits_trend_sale_text ); ?></p>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>

    <?php if (get_theme_mod('fashion_outfits_trend_product_section_on_off_setting', false)) { ?>
        <section class="product pb-5">
            <div class="container">
                <?php
                    $fashion_outfits_trend_product_heading = get_theme_mod( 'fashion_outfits_trend_product_heading', 'Limited time offer' );
                    if ( ! empty( $fashion_outfits_trend_product_heading ) ) { ?>
                    <div class="main-heading">
                        <h3 class="mb-0"><?php echo esc_html( $fashion_outfits_trend_product_heading ); ?></h3>
                    </div>
                <?php } ?>
                <?php
                    $fashion_outfits_trend_product_paragraph = get_theme_mod( 'fashion_outfits_trend_product_paragraph', 'It\'s go time 50 off almost everything till may 21, to june 20' );
                    if ( ! empty( $fashion_outfits_trend_product_paragraph ) ) { ?>
                    <div class="main-heading">
                        <p class="mb-0"><?php echo esc_html( $fashion_outfits_trend_product_paragraph ); ?></p>
                    </div>
                <?php } ?>

                <div class="countdown-container">
                    <div id="countdown" class="mt-4 mb-5">
                        <i class="fa-solid fa-bell"></i>
                        <div><span id="days"><?php esc_html_e('00', 'fashion-outfits-trend'); ?></span><p><?php esc_html_e('Days', 'fashion-outfits-trend'); ?></p></div>
                        <div><span id="hours"><?php esc_html_e('00', 'fashion-outfits-trend'); ?></span><p><?php esc_html_e('Hours', 'fashion-outfits-trend'); ?></p></div>
                        <div><span id="minutes"><?php esc_html_e('00', 'fashion-outfits-trend'); ?></span><p><?php esc_html_e('Minutes', 'fashion-outfits-trend'); ?></p></div>
                        <div><span id="seconds"><?php esc_html_e('00', 'fashion-outfits-trend'); ?></span><p><?php esc_html_e('Seconds', 'fashion-outfits-trend'); ?></p></div>
                    </div>
                </div>

                <div class="tabs-stage">
                    <?php 
                    $category_name = get_theme_mod('fashion_outfits_trend_trending_post_slider_args','product_cat1');
                    if (!empty($category_name)) {
                        // Set query arguments
                        $args = array(
                            'post_type'           => 'product',
                            'ignore_sticky_posts' => true,
                            'posts_per_page'      => 15,
                            'tax_query'           => array(
                                array(
                                    'taxonomy' => 'product_cat',
                                    'field'    => 'slug',
                                    'terms'    => $category_name,
                                    'operator' => 'IN',
                                ),
                            ),
                        );

                        $loop = new WP_Query($args); ?>
                        <div class="owl-carousel">
                            <?php if ($loop->have_posts()) : 
                                while ($loop->have_posts()) : $loop->the_post();
                                    $product = wc_get_product(get_the_ID()); ?>
                                    <div class="box mb-4">
                                        <div class="product-image-box">
                                            <?php if (has_post_thumbnail()) : ?>
                                                <?php the_post_thumbnail(); ?>
                                            <?php endif; ?>
                                            <div class="add-to-cart">
                                                <?php if ($product->is_in_stock()) : ?>
                                                    <?php woocommerce_template_loop_add_to_cart(); ?>
                                                <?php else : ?>
                                                    <button class="button out-of-stock" disabled><?php esc_html_e('Out of Stock', 'fashion-outfits-trend'); ?></button>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                        <div class="box-content">
                                            <?php
                                                global $product;
                                                $average = $product->get_average_rating();
                                                echo wc_get_rating_html($average);
                                            ?>
                                            <h3 class="mb-0">
                                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                            </h3>
                                            <div class="price">
                                                <?php echo $product ? $product->get_price_html() : ''; ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php endwhile;
                            else : ?>
                                <p class="no-products"><?php esc_html_e('No products found.', 'fashion-outfits-trend'); ?></p>
                            <?php endif; ?>
                            <?php wp_reset_postdata(); // Reset post data to avoid conflicts ?>
                        </div>
                    <?php }
                    ?>
                    <div class="shop-now-btn text-center">
                        <?php
                            $fashion_outfits_trend_shop_now_btn = get_theme_mod( 'fashion_outfits_trend_shop_now_btn', 'Shop Now' );
                            $fashion_outfits_trend_shop_now_btn_link = get_theme_mod( 'fashion_outfits_trend_shop_now_btn_link', '#' );
                            if ( ! empty( $fashion_outfits_trend_shop_now_btn ) ) { ?>
                            <a href="<?php echo esc_url( $fashion_outfits_trend_shop_now_btn_link ); ?>"><?php echo esc_html( $fashion_outfits_trend_shop_now_btn ); ?></a>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>    
</main>

<?php
get_footer();

?>