<?php
/**
 * Template part for displaying product section
 *
 * @package Restaurant Eatery
 * @subpackage restaurant_eatery
 */

$restaurant_eatery_aboutus = get_theme_mod('restaurant_eatery_our_products_show_hide_section', false);

if ($restaurant_eatery_aboutus == true) {
?>
<section id="product-section" class="py-5">
  <div class="container">
    <div class="row">
      <div class="col-lg-4 col-md-6 align-self-center">
        <div class="sec-titles mb-4">
          <?php
          $restaurant_eatery_product_content = get_theme_mod('restaurant_eatery_our_products_discount_Text');
          if (!empty($restaurant_eatery_product_content)) : ?>
            <span class="product-content">
              <?php echo esc_html($restaurant_eatery_product_content); ?>
            </span>
          <?php endif; ?>
          <?php
          $restaurant_eatery_prod_heading = get_theme_mod('restaurant_eatery_our_products_heading_section');
          if (!empty($restaurant_eatery_prod_heading)) : ?>
            <h2 class="product-heading">
              <?php echo esc_html($restaurant_eatery_prod_heading); ?>
            </h2>
          <?php endif; ?>
        </div>
      </div>
      <?php
      $restaurant_eatery_selected_category = get_theme_mod('restaurant_eatery_our_product_product_category');
      if ($restaurant_eatery_selected_category) {
        $restaurant_eatery_args = array(
          'post_type'      => 'product',
          'posts_per_page' => 5,
          'product_cat'    => esc_attr($restaurant_eatery_selected_category),
          'order'          => 'ASC'
        );
        $restaurant_eatery_loop = new WP_Query($restaurant_eatery_args);
        if ($restaurant_eatery_loop->have_posts()) : 
          while ($restaurant_eatery_loop->have_posts()) : $restaurant_eatery_loop->the_post();
            $product = wc_get_product(get_the_ID());
            ?>
            <div class="col-lg-4 col-md-6">
              <div class="item mb-4">
                <div class="row">
                  <div class="col-xl-4 col-lg-5 col-md-5 align-self-center pe-lg-0">
                    <div class="product-image position-relative">
                      <?php echo wp_kses_post($product->get_image()); ?>
                      <div class="bottom-cart">
                        <p class="product-price" style="color: <?php echo esc_attr($product->is_on_sale() ? 'black' : 'gray'); ?>">
                          <?php echo wp_kses_post($product->get_price_html()); ?>
                        </p>
                        <div class="cart-button">
                          <a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" data-quantity="1" class="add-to-cart-icon add_to_cart_button ajax_add_to_cart" data-product_id="<?php echo esc_attr( $product->get_id() ); ?>" aria-label="<?php echo esc_attr( $product->add_to_cart_text() ); ?>" rel="nofollow" title="Add to Cart">
                          <i class="fa fa-shopping-cart"></i>
                        </a>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-xl-8 col-lg-7 col-md-7 align-self-center">
                    <div class="product-box">
                      <div class="product-content text-md-start mt-md-0 mt-3">
                        <h4 class=""><a href="<?php the_permalink(); ?>"><?php echo esc_html(get_the_title()); ?></a></h4>
                        <div class="serv-tags">
                          <?php
                            $restaurant_eatery_product_tags = wp_get_post_terms(get_the_ID(), 'product_tag');
                            if ($restaurant_eatery_product_tags && !is_wp_error($restaurant_eatery_product_tags)) {
                              $restaurant_eatery_display_tags = array_slice($restaurant_eatery_product_tags, 0, 3);
                              echo '<div class="produ-tags">';
                              foreach ($restaurant_eatery_display_tags as $restaurant_eatery_i => $tag) {
                                echo '<a href="' . esc_url(get_term_link($tag->term_id, 'product_tag')) . '" class="me-2 mb-3 tag-link tag-link' . ($restaurant_eatery_i + 1) . '">' . esc_html($tag->name) . '</a>';
                              }
                              echo '</div>';
                            }
                          ?>
                        </div>
                        <p class="product-description">
                          <?php echo esc_html( restaurant_eatery_string_limit_words($product->get_description(), 15) ); ?>
                        </p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          <?php
          endwhile;
          wp_reset_postdata();
        endif;
      } ?>
    </div>
  </div>
</section>
<?php } ?>