<?php
/**
 * Template part for displaying slider section
 *
 * @package Doctor General Physician
 * @subpackage doctor_general_physician
 */

$doctor_general_physician_static_image = get_stylesheet_directory_uri() . '/assets/images/header_img.png';
$doctor_general_physician_slider_arrows = get_theme_mod('doctor_general_physician_slider_arrows',true);
?>

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

      if (!empty($doctor_general_physician_slide_pages)) :
        $doctor_general_physician_args = array(
          'post_type' => 'page',
          'post__in' => $doctor_general_physician_slide_pages,
          'orderby' => 'post__in'
        );
        $doctor_general_physician_query = new WP_Query($doctor_general_physician_args);
        if ($doctor_general_physician_query->have_posts()) :
          while ($doctor_general_physician_query->have_posts()) : $doctor_general_physician_query->the_post(); ?>
            <div class="item">
              <div class="row">
                <div class="col-lg-6 col-md-6 col-12 slider-content-col align-self-center">
                  <div class="carousel-caption">
                    <div class="inner_carousel">
                      <?php if (get_theme_mod('doctor_general_physician_show_slider_title', true)) : ?>
                        <?php
                        $doctor_general_physician_title = get_the_title();
                        $doctor_general_physician_title_words = explode(' ', $doctor_general_physician_title);
                        $doctor_general_physician_word_count = count($doctor_general_physician_title_words);
                        $doctor_general_physician_highlighted_title = '';

                        foreach ($doctor_general_physician_title_words as $doctor_general_physician_index => $doctor_general_physician_word) {
                            // Highlight the first two words
                            if ($doctor_general_physician_index < 2) {
                                $doctor_general_physician_highlighted_title .= '<span class="highlighted-word">' . esc_html($doctor_general_physician_word) . '</span>';
                            } else {
                                $doctor_general_physician_highlighted_title .= esc_html($doctor_general_physician_word);
                            }

                            // Add a space between words (but not after the last word)
                            if ($doctor_general_physician_index < $doctor_general_physician_word_count - 1) {
                                $doctor_general_physician_highlighted_title .= ' ';
                            }
                        }
                        ?>

                        <h1 class="mb-2">
                            <a href="<?php the_permalink(); ?>" class="text-capitalize"><?php echo $doctor_general_physician_highlighted_title; ?></a>
                        </h1>
                      <?php endif; ?>
                      <?php if (get_theme_mod('doctor_general_physician_show_slider_content', true)) : ?>
                        <p class="mb-2"><?php $doctor_general_physician_excerpt = get_the_excerpt(); echo esc_html( doctor_general_physician_string_limit_words( $doctor_general_physician_excerpt, esc_attr(get_theme_mod('doctor_general_physician_slider_excerpt_length','50')))); ?></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', 'doctor-general-physician'); ?></a>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-6 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($doctor_general_physician_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'doctor-general-physician'); ?>" />
                  <?php endif; ?>
                </div>
              </div>
            </div>
          <?php endwhile;
          wp_reset_postdata();
        else : ?>
          <div class="no-postfound"><?php esc_html_e('No posts found', 'doctor-general-physician'); ?></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('doctor_general_physician_customer_review', '')); ?></span>

                    <?php if (get_theme_mod('doctor_general_physician_customer_review')) : ?>
                        <div class="customer-review"><?php esc_html_e('Patient Recover', 'doctor-general-physician'); ?></div>
                    <?php endif; ?>
                </div>
                <?php 
                $doctor_general_physician_selected_category = get_theme_mod('doctor_general_physician_about_catData', 'select');
                if ($doctor_general_physician_selected_category != 'select') { ?>
                  <div class="half-width-border-top">
                    <div class="abt-cat">
                        <div class="owl-carousel m-0">
                            <?php
                            $doctor_general_physician_abtpage_query = new WP_Query(array(
                                'category_name' => esc_attr($doctor_general_physician_selected_category),
                                'posts_per_page' => -1,
                            ));
                            if ($doctor_general_physician_abtpage_query->have_posts()) :
                                while ($doctor_general_physician_abtpage_query->have_posts()) : $doctor_general_physician_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($doctor_general_physician_static_image); ?>" alt="<?php esc_attr_e('Default image', 'doctor-general-physician'); ?>" />
                                        <?php } ?>
                                    </div>
                                <?php endwhile;
                                wp_reset_postdata();
                            else : ?>
                                <p><?php esc_html_e('No posts found in this category.', 'doctor-general-physician'); ?></p>
                            <?php endif; ?>
                        </div>
                    </div>
                  </div>
                <?php } ?>
              </div>
            </div>
        </div>
      </div>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>