<?php if (get_theme_mod('vegan_cafe_restaurant_project_show_hide', 1)) : ?>
    <?php if (class_exists('WooCommerce')) : // Check if WooCommerce is active ?>
        <section id="projetcs-sec" class="my-5">
            <div class="container">
                <div class="title-head">
                    <?php if (get_theme_mod('vegan_cafe_restaurant_projects_main_heading') != '') { ?>
                        <h2 class="text-center mb-lg-3 mb-4"><?php echo esc_html(get_theme_mod('vegan_cafe_restaurant_projects_main_heading', '')); ?></h2>
                    <?php } ?>
                </div>
                <div class="tab text-center">
                    <?php
                    $vegan_cafe_restaurant_total_tabs = get_theme_mod('vegan_cafe_restaurant_projects_number', 4);
                    for ($vegan_cafe_restaurant_j = 1; $vegan_cafe_restaurant_j <= $vegan_cafe_restaurant_total_tabs; $vegan_cafe_restaurant_j++) {
                        $vegan_cafe_restaurant_tab_text = get_theme_mod("vegan_cafe_restaurant_tab_name_{$vegan_cafe_restaurant_j}");
                        $vegan_cafe_restaurant_tab_id = str_replace(' ', '-', $vegan_cafe_restaurant_tab_text);
                        if (!empty($vegan_cafe_restaurant_tab_text)) { ?>
                            <button class="tablinks" onclick="vegan_cafe_restaurant_projetcs_tab(event, '<?php echo esc_attr($vegan_cafe_restaurant_tab_id); ?>')">
                                <?php echo esc_html($vegan_cafe_restaurant_tab_text); ?>
                            </button>
                        <?php }
                    } ?>
                </div>
                <?php for ($vegan_cafe_restaurant_j = 1; $vegan_cafe_restaurant_j <= $vegan_cafe_restaurant_total_tabs; $vegan_cafe_restaurant_j++) {
                    $vegan_cafe_restaurant_tab_text = get_theme_mod("vegan_cafe_restaurant_tab_name_{$vegan_cafe_restaurant_j}");
                    $vegan_cafe_restaurant_tab_id = str_replace(' ', '-', $vegan_cafe_restaurant_tab_text);
                    $vegan_cafe_restaurant_category_product = get_theme_mod("vegan_cafe_restaurant_projects_category_{$vegan_cafe_restaurant_j}",'product_cat1');
                    $vegan_cafe_restaurant_products_to_show = get_theme_mod("vegan_cafe_restaurant_products_to_show_{$vegan_cafe_restaurant_j}", 4);
                    if (!empty($vegan_cafe_restaurant_tab_text) && !empty($vegan_cafe_restaurant_category_product)) { ?>
                        <div id="<?php echo esc_attr($vegan_cafe_restaurant_tab_id); ?>" class="tabcontent mt-3">
                            <div class="row">
                                <?php
                                $query_args = array(
                                    'post_type'      => 'product',
                                    'posts_per_page' => $vegan_cafe_restaurant_products_to_show,
                                    'tax_query'      => array(
                                        array(
                                            'taxonomy' => 'product_cat',
                                            'field'    => 'slug',
                                            'terms'    => $vegan_cafe_restaurant_category_product,
                                        ),
                                    ),
                                );
                                $product_query = new WP_Query($query_args);
                                $product_index = 1;

                                if ($product_query->have_posts()) :
                                    while ($product_query->have_posts()) : $product_query->the_post();
                                        $vegan_cafe_restaurant_custom_location = get_theme_mod("vegan_cafe_restaurant_projects_location_{$vegan_cafe_restaurant_j}_{$product_index}",'Hawaii');
                                        $vegan_cafe_restaurant_custom_no_people = get_theme_mod("vegan_cafe_restaurant_no_people_{$vegan_cafe_restaurant_j}_{$product_index}",'56 - people');

                                        // Get the WooCommerce product object
                                        $product = wc_get_product(get_the_ID());
                                        if ($product) :
                                ?>
                                    <div class="col-lg-3 col-md-6 wow zoomIn" data-wow-delay="0.5s">
                                        <div class="box mb-4">
                                            <?php if (has_post_thumbnail()) { ?>
                                                <?php the_post_thumbnail(); ?>
                                            <?php } else { ?>
                                                <div class="post-color"></div>
                                            <?php } ?>
                                            <div class="box-content">
                                                <div class="row">
                                                    <div class="col-lg-9 col-md-9 col-9 align-self-center">
                                                        <h3 class="serv-title my-lg-2 mt-2 mb-0"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                                    </div>
                                                    <div class="col-lg-3 col-md-3 col-3 align-self-center">
                                                        <div class="star-rating d-flex justify-content-end">
                                                            <?php if ($product->get_average_rating() > 0) {
                                                                printf(
                                                                    '<div class="product-rating"><span class="star-icon">&#9733;</span> %s</div>',
                                                                    esc_html(number_format($product->get_average_rating(), 1))
                                                                );
                                                            } ?>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="table-people d-flex mb-2">
                                                    <p class="my-0 product-price me-lg-3 me-2">
                                                        <?php echo '<span class="product-price">' . wp_kses_post($product->get_price_html()) . '</span>'; ?>
                                                    </p>
                                                    <?php if (!empty($vegan_cafe_restaurant_custom_no_people)) : ?>
                                                        <p class="total-ppl"><?php echo esc_html($vegan_cafe_restaurant_custom_no_people); ?></p>
                                                    <?php endif; ?>
                                                </div>
                                                <?php if (!empty($vegan_cafe_restaurant_custom_location)) : ?>
                                                    <p class="location-cafe"><i class="fas fa-map-marker-alt"></i> <span><?php echo esc_html($vegan_cafe_restaurant_custom_location); ?></span></p>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php
                                    endif; // End if $product
                                    $product_index++;
                                    endwhile;
                                    wp_reset_postdata();
                                endif;
                                ?>
                            </div>
                        </div>
                    <?php } ?>
                <?php } ?>
            </div>
        </section>
    <?php else : ?>
        <p class="text-center"><?php esc_html_e('WooCommerce is not active. Please install and activate WooCommerce to display products Section.', 'vegan-cafe-restaurant'); ?></p>
    <?php endif; ?>
<?php endif; ?>