<?php

$expert_dental_specialist_static_image = get_stylesheet_directory_uri() . '/assets/images/slider-img.png';
$expert_dental_specialist_post_image = get_stylesheet_directory_uri() . '/assets/images/post-img.png';
$expert_dental_specialist_slider_arrows = get_theme_mod('expert_dental_specialist_slider_arrows', false);
?>

<?php if ($expert_dental_specialist_slider_arrows) : ?>
  <section id="slider" style="background-image: url('<?php echo get_stylesheet_directory_uri(); ?>/assets/images/slider-bg.png');">
    <div class="main-slide owl-carousel owl-theme">
      <?php 
      $expert_dental_specialist_slide_pages = array();
      for ($expert_dental_specialist_count = 1; $expert_dental_specialist_count <= 4; $expert_dental_specialist_count++) {
        $mod = absint(get_theme_mod('expert_dental_specialist_slider_page' . $expert_dental_specialist_count));
        if ($mod != 0) {
          $expert_dental_specialist_slide_pages[] = $mod;
        }
      }

      if (!empty($expert_dental_specialist_slide_pages)) :
        $expert_dental_specialist_args = array(
          'post_type' => 'page',
          'post__in' => $expert_dental_specialist_slide_pages,
          'orderby' => 'post__in'
        );
        $expert_dental_specialist_query = new WP_Query($expert_dental_specialist_args);
        if ($expert_dental_specialist_query->have_posts()) :
          while ($expert_dental_specialist_query->have_posts()) : $expert_dental_specialist_query->the_post(); ?>
            <div class="item">
              <div class="row">
                <div class="col-lg-7 col-md-6 col-12 slider-content-col align-self-center wow fadeInRight" data-wow-delay="0.5s">
                  <div class="carousel-caption">
                    <div class="inner_carousel">
                      <?php if (get_theme_mod('expert_dental_specialist_show_slider_title', true)) : ?>
                        <?php
                        $expert_dental_specialist_title = get_the_title();
                        $expert_dental_specialist_title_words = explode(' ', $expert_dental_specialist_title);
                        $expert_dental_specialist_word_count = count($expert_dental_specialist_title_words);
                        $expert_dental_specialist_highlighted_title = '';

                        foreach ($expert_dental_specialist_title_words as $expert_dental_specialist_index => $expert_dental_specialist_word) {
                            // Highlight the first two words
                            if ($expert_dental_specialist_index < 2) {
                                $expert_dental_specialist_highlighted_title .= '<span class="highlighted-word">' . esc_html($expert_dental_specialist_word) . '</span>';
                            } else {
                                $expert_dental_specialist_highlighted_title .= esc_html($expert_dental_specialist_word);
                            }

                            // Add a space between words (but not after the last word)
                            if ($expert_dental_specialist_index < $expert_dental_specialist_word_count - 1) {
                                $expert_dental_specialist_highlighted_title .= ' ';
                            }
                        }
                        ?>
                        <h1 class="mb-2">
                          <a href="<?php the_permalink(); ?>" class="text-capitalize"><?php echo $expert_dental_specialist_highlighted_title; ?></a>
                        </h1>
                      <?php endif; ?>
                      <?php if (get_theme_mod('expert_dental_specialist_show_slider_content', true)) : ?>
                        <p class="mb-2 slider-content"><?php echo wp_kses_post(wp_trim_words(get_the_content(), 40)); ?></p>
                      <?php endif; ?>
                      <div class="more-btn mt-4">
                        <a href="<?php the_permalink(); ?>" class="text-capitalize me-lg-4 me-md-3 me-2 mb-3 slider-btn1"><?php esc_html_e('Make An Appointment', 'expert-dental-specialist'); ?></a>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-5 col-md-6 col-12 slider-img-col align-self-center">
                  <?php if (has_post_thumbnail()) : ?>
                    <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>" />
                  <?php else : ?>
                    <img src="<?php echo esc_url($expert_dental_specialist_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'expert-dental-specialist'); ?>" />
                  <?php endif; ?>
                </div>
              </div>
            </div>
          <?php endwhile;
          wp_reset_postdata();
        else : ?>
          <div class="no-postfound"><?php esc_html_e('No posts found', 'expert-dental-specialist'); ?></div>
        <?php endif;
      endif; ?>
    </div>

    <div class="row">
      <div class="container">
        <div class="col-lg-9 col-md-9">
        </div>
        <div class="col-lg-3 col-md-3 col-12">
            <div class="rating-col">
              <div class="rating-box">
                <div class="customzer-rating">
                    <span class="rate-no"><?php echo esc_html(get_theme_mod('expert_dental_specialist_customer_review', '10k+')); ?></span>

                    <?php if (get_theme_mod('expert_dental_specialist_customer_review', '10k+')) : ?>
                        <div class="customer-review"><?php esc_html_e('Patient Recover', 'expert-dental-specialist'); ?></div>
                    <?php endif; ?>
                </div>
                <?php 
                $expert_dental_specialist_selected_category = get_theme_mod('expert_dental_specialist_about_catData', 'uncategorized');
                if ($expert_dental_specialist_selected_category != 'select') { ?>
                  <div class="half-width-border-top">
                    <div class="abt-cat">
                        <div class="owl-carousel m-0">
                            <?php
                            $expert_dental_specialist_abtpage_query = new WP_Query(array(
                                'category_name' => esc_attr($expert_dental_specialist_selected_category),
                                'posts_per_page' => -1,
                            ));
                            if ($expert_dental_specialist_abtpage_query->have_posts()) :
                                while ($expert_dental_specialist_abtpage_query->have_posts()) : $expert_dental_specialist_abtpage_query->the_post(); ?>
                                    <div class="abt-imagebox">
                                        <?php if (has_post_thumbnail()) { ?>
                                            <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title_attribute(); ?>" />
                                        <?php } else { ?>
                                            <img src="<?php echo esc_url($expert_dental_specialist_post_image); ?>" alt="<?php esc_attr_e('Default image', 'expert-dental-specialist'); ?>" />
                                        <?php } ?>
                                    </div>
                                <?php endwhile;
                                wp_reset_postdata();
                            else : ?>
                                <p><?php esc_html_e('No posts found in this category.', 'expert-dental-specialist'); ?></p>
                            <?php endif; ?>
                        </div>
                    </div>
                  </div>
                <?php } ?>
              </div>
            </div>
        </div>
      </div>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>