<?php
/**
 * Template Name: Home Template
 */

get_header(); ?>

<main id="skip-content">
  <?php if (get_theme_mod('automobile_detailing_shop_slider_section_setting', false) != '') { ?>
    <section id="top-slider">
      <?php $automobile_detailing_shop_slide_pages = array();
        for ( $automobile_detailing_shop_count = 1; $automobile_detailing_shop_count <= 3; $automobile_detailing_shop_count++ ) {
          $automobile_detailing_shop_mod = intval( get_theme_mod( 'automobile_detailing_shop_top_slider_page' . $automobile_detailing_shop_count ));
          if ( 'page-none-selected' != $automobile_detailing_shop_mod ) {
            $automobile_detailing_shop_slide_pages[] = $automobile_detailing_shop_mod;
          }
        }
        if( !empty($automobile_detailing_shop_slide_pages) ) :
          $automobile_detailing_shop_args = array(
            'post_type' => 'page',
            'post__in' => $automobile_detailing_shop_slide_pages,
            'orderby' => 'post__in'
          );
          $automobile_detailing_shop_query = new WP_Query( $automobile_detailing_shop_args );
          if ( $automobile_detailing_shop_query->have_posts() ) :
            $i = 1;
      ?>
      <div class="owl-carousel" role="listbox">
        <?php  while ( $automobile_detailing_shop_query->have_posts() ) : $automobile_detailing_shop_query->the_post(); ?>
          <div class="slide-box" data-count="<?php echo $i; ?>" >
            <div class="slider-image">
              <?php if(has_post_thumbnail()){
                the_post_thumbnail();
                } else{?>
                <img class="main-image-default" src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
              <?php } ?>
            </div>
            <div class="slider-inner-box">
              <?php if(get_theme_mod('automobile_detailing_shop_slider_short_heading') != ''){ ?>
                <h5 class="main-heading mb-4 ps-4"><?php echo esc_html(get_theme_mod('automobile_detailing_shop_slider_short_heading')); ?></h5>
              <?php }?>
              <h3 class="m-0 mb-1"><?php the_title(); ?></h3>
              <p><?php echo wp_trim_words( get_the_content(), 15 ); ?></p>
              <div class="slide-btn mt-4">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More','automobile-detailing-shop'); ?></a>
              </div>
            </div>
          </div>
        <?php $i++; endwhile;
        wp_reset_postdata();?>
      </div>
      <?php else : ?>
        <div class="no-postfound"></div>
      <?php endif;
      endif;?>
      <div class="video-image-box">
        <?php if(get_theme_mod('automobile_detailing_shop_slider_video_button_url') != ''){ ?>
          <div class="slide-button">
            <!-- Button to open the modal -->
            <div class="video-image">
              <span class="image-video-btn">
                <a id="openModalButton" data-modal-src="<?php echo esc_url(get_theme_mod('automobile_detailing_shop_slider_video_button_url')); ?>"><i class="fas fa-play"></i></a>
                <!-- The modal -->
            <div id="myModal" class="modal">
              <!-- Modal content -->
              <div class="modal-content">
                <span id="closeModalButton" class="close">&times;</span>
                <?php if( get_theme_mod('automobile_detailing_shop_slider_video_button_url') != ''){ ?>
                <embed id="videoPlayer" height="369" src="<?php echo esc_url(get_theme_mod('automobile_detailing_shop_slider_video_button_url')); ?>"  allow="accelerometer; autoplay; classipboard-write; gyroscope; picture-in-picture" allowfullscreen></embed>
                <?php }else{ ?>
                  <h3><?php esc_html_e('Add Video Url In Customizer To Display Video Here','automobile-detailing-shop'); ?></h3>
                <?php } ?>
              </div>
            </div> 
              </span>
            </div>            
          </div>
        <?php } ?>
      </div>
    </section>
  <?php }?>
  <?php if (get_theme_mod('automobile_detailing_shop_service_section_setting', false) != '') { ?>
    <section id="service-section" class="py-5">
      <div class="container">
        <div class="row mb-4">
          <div class="col-lg-8 col-md-8 col-sm-8 align-self-center">
            <div class="service-head">
              <?php if(get_theme_mod('automobile_detailing_shop_service_sub_heading') != ''){ ?>
                <h6 class=""><?php echo esc_html(get_theme_mod('automobile_detailing_shop_service_sub_heading')); ?></h6>
              <?php }?>
              <?php if(get_theme_mod('automobile_detailing_shop_service_heading') != ''){ ?>
                <h3 class="main-heading mb-0"><?php echo esc_html(get_theme_mod('automobile_detailing_shop_service_heading')); ?></h3>
              <?php }?>
            </div>
          </div>
          <div class="col-lg-4 col-md-4 col-sm-4 align-self-center">
            <?php if(get_theme_mod('automobile_detailing_shop_service_button_url') != '' || get_theme_mod('automobile_detailing_shop_service_button_text') != ''){ ?>
              <div class="experience-btn text-end">
                <a href="<?php echo esc_url(get_theme_mod('automobile_detailing_shop_service_button_url')); ?>"><?php echo esc_html(get_theme_mod('automobile_detailing_shop_service_button_text')); ?></a>
              </div>
            <?php }?>
          </div>
        </div>
        
        <div class="owl-carousel" role="listbox">
          <?php
            $automobile_detailing_shop_service_category = get_theme_mod('automobile_detailing_shop_service_category','');
            if($automobile_detailing_shop_service_category){
              $automobile_detailing_shop_page_query5 = new WP_Query(array( 'category_name' => esc_html($automobile_detailing_shop_service_category,'automobile-detailing-shop'), 'posts_per_page' => esc_attr(get_theme_mod('automobile_detailing_shop_service_number',3))));
              $i=1;
              while( $automobile_detailing_shop_page_query5->have_posts() ) : $automobile_detailing_shop_page_query5->the_post(); ?>
                <div class="service-box">
                  <?php if(get_theme_mod('automobile_detailing_shop_service_icon'.$i) != ''){ ?>
                    <div class="service-icon">
                      <i class="<?php echo esc_html(get_theme_mod('automobile_detailing_shop_service_icon'.$i)); ?>"></i>
                    </div>
                  <?php }?>
                  <div class="service-content">
                    <h4 class="mb-2"><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words(get_the_title(), 8, '...'); ?></a></h4>
                    <p><?php echo wp_trim_words( get_the_content(), 15 ); ?></p>
                    <?php
                      // Get values from Customizer as pure numbers
                      $automobile_detailing_shop_raised = floatval( get_theme_mod( 'automobile_detailing_shop_service_raised_amount'. $i,80  ) );
                      $automobile_detailing_shop_goal   = 100;

                      $automobile_detailing_shop_percent = ($automobile_detailing_shop_goal > 0) ? ($automobile_detailing_shop_raised / $automobile_detailing_shop_goal * 100) : 0;
                        if ($automobile_detailing_shop_percent > 100) $automobile_detailing_shop_percent = 100;
                        ?>
                        <div class="progress-container">
                          <div class="progress-labels">
                            <span>0%</span>
                            <span><?php echo round($automobile_detailing_shop_percent); ?>%</span>
                          </div>
                          <div class="progress-bar">
                            <div class="progress-fill" style="width: <?php echo esc_attr( $automobile_detailing_shop_percent ); ?>%;"></div>
                          </div>
                        </div>
                  </div>
                </div>
              <?php $i++; endwhile;
            wp_reset_postdata();
          } ?>
        </div>
      </div>
    </section>
  <?php }?>
  <section id="page-content">
    <div class="container">
      <div class="py-5">
        <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              the_content();
            endwhile;
          endif;
        ?>
      </div>
    </div>
  </section>
</main>

<?php get_footer(); ?>