<?php
/**
 * Template part for displaying about section
 *
 * @package Online Education LMS
 * @subpackage online_education_lms
 */

$online_education_lms_static_image = get_stylesheet_directory_uri() . '/assets/images/about-img.png';

$online_education_lms_static_image1 = get_stylesheet_directory_uri() . '/assets/images/customer1.png';

if (get_theme_mod('online_education_lms_service_enable', true) != '') : ?>
<section id="service" class="my-5">
    <div class="container">
        <?php
        $online_education_lms_about_page_id = absint(get_theme_mod('online_education_lms_about_page'));
        if ($online_education_lms_about_page_id != 0) : 
            $online_education_lms_args = array(
                'post_type' => 'page',
                'p' => $online_education_lms_about_page_id
            );
            $online_education_lms_query = new WP_Query($online_education_lms_args);
            if ($online_education_lms_query->have_posts()) :
                while ($online_education_lms_query->have_posts()) : $online_education_lms_query->the_post(); ?>
                    <div class="row">
                      <div class="col-xl-3 col-lg-4 col-md-4">
                        <div class="about-left-img mb-3">
                          <?php
                              $online_education_lms_about_bg = get_theme_mod('online_education_lms_about_bg');
                              $online_education_lms_default_img = get_stylesheet_directory_uri() . '/assets/images/about-bg.png'; 
                          ?>
                          <div class="<?php echo empty($online_education_lms_about_bg) ? 'no-image1' : ''; ?>">
                            <?php if (!empty($online_education_lms_about_bg)) : ?>
                              <img src="<?php echo esc_url($online_education_lms_about_bg); ?>" alt="<?php esc_attr_e('Background Image 1', 'online-education-lms'); ?>" />
                            <?php else: ?>
                              <img src="<?php echo esc_url($online_education_lms_default_img); ?>" alt="<?php esc_attr_e('Default Background Image 1', 'online-education-lms'); ?>" />
                            <?php endif; ?>
                          </div>
                        </div>
                          <div class="about-left-video thumbnail mb-3">
                            <?php
                                $online_education_lms_about_video_bg = get_theme_mod('online_education_lms_about_video_bg');
                                $online_education_lms_video_img = get_stylesheet_directory_uri() . '/assets/images/abt-video.png'; 
                            ?>
                            <div class="image-wrapper <?php echo empty($online_education_lms_about_video_bg) ? 'no-image1' : ''; ?>">
                              <?php if (!empty($online_education_lms_about_video_bg)) : ?>
                                <img src="<?php echo esc_url($online_education_lms_about_video_bg); ?>" alt="<?php esc_attr_e('Background Image 2', 'online-education-lms'); ?>" />
                              <?php else: ?>
                                <img src="<?php echo esc_url($online_education_lms_video_img); ?>" alt="<?php esc_attr_e('Default Background Image 2', 'online-education-lms'); ?>" />
                              <?php endif; ?>
                            </div>
                            <?php
                            // Get the YouTube URL
                            $online_education_lms_youtube_url = get_theme_mod('online_education_lms_youtube_url','');
                            if (!empty($online_education_lms_youtube_url)) : ?>
                                <a href="<?php echo esc_url($online_education_lms_youtube_url); ?>" class="youtube-icon-overlay" target="_blank" rel="noopener">
                                    <i class="fas fa-play"></i>
                                </a>
                            <?php endif; ?>
                          </div>
                        </div>
                      <div class="col-xl-9 col-lg-8 col-md-8 image-abt position-relative">
                        <div class="match-heading position-relative">
                              <?php if (get_theme_mod('online_education_lms_service_sub_heading') != '') : ?>
                                <h2 class="serv-short m-0 text-capitalize"><i class="fas fa-graduation-cap me-2"></i> <?php echo esc_html(get_theme_mod('online_education_lms_service_sub_heading')); ?></h2>
                              <?php endif; ?>
                          </div>
                          <?php
                          $online_education_lms_title = get_the_title();
                          $online_education_lms_words = explode(' ', $online_education_lms_title);
                          $online_education_lms_word_count = count($online_education_lms_words);

                          if ( $online_education_lms_word_count >= 7 ) {
                              // Highlight the 7th word (array index 6)
                              $online_education_lms_words[6] = '<span class="middle-word">' . esc_html($online_education_lms_words[6]) . '</span>';
                              $online_education_lms_modified_title = implode(' ', $online_education_lms_words);
                          } else {
                              $online_education_lms_modified_title = esc_html($online_education_lms_title);
                          }
                          ?>
                          <h3 class="mt-3 mb-2">
                              <a href="<?php the_permalink(); ?>">
                                  <?php echo wp_kses_post($online_education_lms_modified_title); ?>
                              </a>
                          </h3>
                          <p class="mb-3 abt-content"><?php echo esc_html(wp_trim_words(get_the_content(), 75)); ?></p>
                        <div class="row">
                          <div class="col-lg-5 col-md-5 about-block">
                              <div class="about-image1 mb-3">
                                  <?php if (has_post_thumbnail()) { ?>
                                      <img src="<?php the_post_thumbnail_url('full'); ?>" />
                                  <?php } else { ?>
                                      <img src="<?php echo esc_url($online_education_lms_static_image); ?>" />
                                  <?php } ?>
                              </div>
                              <div class="rating-col my-3">
                                      <div class="row rating-box">
                                        <div class="col-lg-7 col-md-6 col-5 align-self-center">
                                          <div class="customzer-rating">
                                            <span class="rate-no"><?php echo esc_html(get_theme_mod('online_education_lms_customer_review', '')); ?></span>
                                            <?php if (get_theme_mod('online_education_lms_customer_review')) : ?>
                                              <div class="customer-review"><?php esc_html_e('Happy Lab Test People', 'online-education-lms'); ?></div>
                                            <?php endif; ?>
                                          </div>
                                        </div>
                                          <div class="col-lg-5 col-md-6 col-7 align-self-center px-0 position-relative">
                                              <?php 
                                              $online_education_lms_selected_category = get_theme_mod('online_education_lms_about_catData', 'select');
                                              if ($online_education_lms_selected_category != 'select') { ?>
                                                  <div class="abt-cat">
                                                      <div class="owl-carousel m-0">
                                                          <?php
                                                          $online_education_lms_abtpage_query = new WP_Query(array(
                                                              'category_name' => esc_attr($online_education_lms_selected_category),
                                                              'posts_per_page' => -1,
                                                          ));
                                                          if ($online_education_lms_abtpage_query->have_posts()) :
                                                              while ($online_education_lms_abtpage_query->have_posts()) : $online_education_lms_abtpage_query->the_post(); ?>
                                                                  <div class="abt-imagebox">
                                                                      <?php if ( has_post_thumbnail() ) { ?>
                                                                        <a href="<?php the_permalink(); ?>">
                                                                            <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title_attribute(); ?>" />
                                                                        </a>
                                                                      <?php } else { ?>
                                                                          <a href="<?php the_permalink(); ?>">
                                                                              <img src="<?php echo esc_url($online_education_lms_static_image1); ?>" alt="<?php esc_attr_e('Default image', 'online-education-lms'); ?>" />
                                                                          </a>
                                                                      <?php } ?>
                                                                  </div>
                                                              <?php endwhile;
                                                              wp_reset_postdata();
                                                          else : ?>
                                                              <p><?php esc_html_e('No posts found in this category.', 'online-education-lms'); ?></p>
                                                          <?php endif; ?>
                                                      </div>
                                                  </div>
                                              <?php } ?>
                                          </div>
                                      </div>
                                  </div>
                          </div>
                          <div class="col-lg-7 col-md-7 col-md-3about-block">
                            <?php 
                              if (
                                  get_theme_mod('online_education_lms_main_tab_heading1') != '' ||
                                  get_theme_mod('online_education_lms_main_tab_heading2') != ''
                              ) : ?>
                              <div class="feature-content-main mb-lg-4 mb-md-3 mb-4">
                                <?php for ($online_education_lms_i = 1; $online_education_lms_i <= 2; $online_education_lms_i++) : ?>
                                    <?php if (get_theme_mod('online_education_lms_main_tab_heading' . $online_education_lms_i) != '') : ?>
                                      <div class="abt-sentences">
                                        <div class="tab-details align-items-center mb-lg-4 mb-md-3 mb-4">
                                          <?php
                                          // Fetch icon setting, fallback to default
                                          $online_education_lms_icon_class = get_theme_mod('online_education_lms_main_tab_icon' . $online_education_lms_i, 'fas fa-university');
                                          ?>
                                          <i class="<?php echo esc_attr($online_education_lms_icon_class); ?>"></i>
                                          <div class="abt-content">
                                            <h4 class="m-0"><?php echo esc_html(get_theme_mod('online_education_lms_main_tab_heading' . $online_education_lms_i)); ?></h4>
                                            <p class="m-0"><?php echo esc_html(get_theme_mod('online_education_lms_main_tab_para' . $online_education_lms_i)); ?></p>
                                          </div>
                                        </div>
                                      </div>
                                    <?php endif; ?>
                                <?php endfor; ?>
                              </div>
                            <?php endif; ?>

                            <?php if (get_theme_mod('online_education_lms_tab_heading1') != '' || get_theme_mod('online_education_lms_tab_heading2') != '' || get_theme_mod('online_education_lms_tab_heading3') != '') : ?>
                                <?php for ($online_education_lms_i = 1; $online_education_lms_i <= 3; $online_education_lms_i++) : ?>
                                    <?php if (get_theme_mod('online_education_lms_tab_heading' . $online_education_lms_i) != '') : ?>
                                        <div class="bottom-tab-details d-flex align-items-center mb-3">
                                            <?php
                                            $online_education_lms_icon_class = get_theme_mod('online_education_lms_tab_icon' . $online_education_lms_i);
                                            if (!$online_education_lms_icon_class) {
                                                $online_education_lms_icon_class = 'fas fa-check'; // Default icon
                                            }
                                            ?>
                                            <i class="me-2 <?php echo esc_attr($online_education_lms_icon_class); ?>"></i>
                                            <h3 class="m-0"><?php echo esc_html(get_theme_mod('online_education_lms_tab_heading' . $online_education_lms_i)); ?></h3>
                                        </div>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php endif; ?>
                            <?php if( get_theme_mod( 'online_education_lms_abt_link' ) != '' && get_theme_mod( 'online_education_lms_abt_button','More About Us' ) != '') { ?>
                              <div class="abt-btn text-left mt-xl-5 mt-lg-3 mt-md-3">
                                <a href="<?php echo esc_url( get_theme_mod( 'online_education_lms_abt_link','' ) ); ?>" class="abt-btn"><?php echo esc_html( get_theme_mod( 'online_education_lms_abt_button','More About Us' ) ); ?><i class="fas fa-chevron-right ms-2"></i></a>
                              </div>
                            <?php } ?>
                          </div>
                        </div>
                      </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata();
            endif;
        endif; ?>
    </div>
</section>
<?php endif; ?>