<?php 
$expert_business_consultant_courses = get_theme_mod('expert_business_consultant_courses_setting', '1');
$expert_business_consultant_courses_button = get_theme_mod('expert_business_consultant_courses_button_setting', '1');

if ($expert_business_consultant_courses == '1') {
?>
<section id="courses-offer" class="py-5 px-md-0 px-3">
  <div class="container">
    <div class="text-center main-sec-title">
      <?php if (get_theme_mod('expert_business_consultant_offer_section_tittle') != '') { ?>
        <h2 class="my-2 text-center text-uppercase"><?php echo esc_html(get_theme_mod('expert_business_consultant_offer_section_tittle', '')); ?></h2>
        <hr>
      <?php } ?>
    </div>
    <?php if (get_theme_mod('expert_business_consultant_offer_section_text') != '') { ?>
      <p class="text-center px-md-5 mx-md-5 serv-description"><?php echo esc_html(get_theme_mod('expert_business_consultant_offer_section_text', '')); ?></p>
    <?php } ?>
    <div class="row mt-4">
      <?php
        $expert_business_consultant_post_category = get_theme_mod('expert_business_consultant_offer_section_category','uncategorized');
        $expert_business_consultant_posts_to_show = get_theme_mod('expert_business_consultant_posts_to_show', 6);

        if ($expert_business_consultant_post_category) {
          $expert_business_consultant_page_query = new WP_Query(array(
            'category_name' => esc_html($expert_business_consultant_post_category, 'expert-business-consultant'),
            'posts_per_page' => $expert_business_consultant_posts_to_show // Set the number of posts to show
          ));

          $expert_business_consultant_post_count = 0;
          while ($expert_business_consultant_page_query->have_posts()) : $expert_business_consultant_page_query->the_post(); 
            $expert_business_consultant_post_count++;
          ?>
            <div class="col-lg-4 col-md-4 mb-4 wow fadeInUp" data-wow-delay="0.5s">
              <div class="cat-inner-box">
                <?php if (has_post_thumbnail()) : ?>
                    <img src="<?php the_post_thumbnail_url('full'); ?>"/>
                <?php else : ?>
                    <div class="course-color"></div>
                <?php endif; ?>
                <div class="mainserv-content">
                  <div class="service-category-name mt-3">
                    <?php the_category(); ?>
                  </div>
                  <?php if (get_post_meta($post->ID, 'expert_business_consultant_trip_amount', true)) { ?>
                    <h4><?php echo esc_html(get_post_meta($post->ID, 'expert_business_consultant_trip_amount', true)); ?></h4>
                  <?php } ?>
                  <div class="offer-box mb-2">
                    <h3 class="mb-2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                  </div>
                  <?php 
                    $expert_business_consultant_star_rating = get_theme_mod('expert_business_consultant_star_rating' . $expert_business_consultant_post_count, '3'); 
                    // Check if the rating is not empty
                    if (!empty($expert_business_consultant_star_rating)) { ?>
                        <div class="star-rating my-3">
                            <?php for ($i = 1; $i <= 5; $i++) {
                              if ($i <= $expert_business_consultant_star_rating) {
                                  echo '<i class="fas fa-star"></i>';
                              } else {
                                  echo '<i class="far fa-star"></i>';
                              }
                            } ?>
                        </div>
                    <?php } ?>
                  <hr>
                  <div class="row">
                    <div class="col-lg-3 col-md-12 align-self-center">
                      <?php if (get_theme_mod('expert_business_consultant_courses_prices' . $expert_business_consultant_post_count) != '') { ?>
                        <p class="cours-price"><?php echo esc_html(get_theme_mod('expert_business_consultant_courses_prices' . $expert_business_consultant_post_count, '')); ?></p>
                      <?php } ?>
                    </div>
                    <div class="col-lg-9 col-md-12 text-lg-end align-self-center">
                      <ul class="post-meta">
                        <li class="pe-lg-3 pe-2">
                          <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>">
                            <i class="fa fa-user pe-1"></i> <?php the_author(); ?>
                          </a>
                        </li>
                        <li class="pe-lg-3 pe-2">
                          <a href="<?php echo esc_url(get_permalink()); ?>#comments">
                            <i class="fa fa-comment pe-1"></i> <?php echo esc_html(get_comments_number($post->ID)); ?>
                          </a>
                        </li>
                        <li>
                          <i class="fas fa-clock pe-1"></i> <?php echo esc_html(get_the_time('H:i')); ?> <?php esc_html_e('HOURS', 'expert-business-consultant'); ?>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          <?php endwhile;
          wp_reset_postdata();
        }
      ?>
    </div>
  </div>
</section>
<?php } ?>