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

get_header(); ?>

<main id="skip-content">
  <?php if (get_theme_mod('vlog_channel_slider_section_setting', false) != '') { ?>
    <section id="top-slider">
      <div class=" slider-right">
        <?php $vlog_channel_slide_pages = array();
          for ( $vlog_channel_count = 1; $vlog_channel_count <= 3; $vlog_channel_count++ ) {
            $vlog_channel_mod = intval( get_theme_mod( 'vlog_channel_top_slider_page' . $vlog_channel_count ));
            if ( 'page-none-selected' != $vlog_channel_mod ) {
              $vlog_channel_slide_pages[] = $vlog_channel_mod;
            }
          }
          if( !empty($vlog_channel_slide_pages) ) :
            $vlog_channel_args = array(
              'post_type' => 'page',
              'post__in' => $vlog_channel_slide_pages,
              'orderby' => 'post__in'
            );
            $vlog_channel_query = new WP_Query( $vlog_channel_args );
            if ( $vlog_channel_query->have_posts() ) :
              $i = 1;
        ?>
        <div id="combinedCarousel" class="owl-carousel" role="listbox">
          <?php  while ( $vlog_channel_query->have_posts() ) : $vlog_channel_query->the_post(); ?>
            <div class="slide-box">
              <div class="slider-image">
                <?php if(has_post_thumbnail()){
                  the_post_thumbnail();
                } else{?>
                  <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
                <?php } ?>
                <div class="slider-background"></div>
              </div>
              <div class="slider-inner-box">
                <?php if(get_theme_mod('vlog_channel_slider_short_heading') != ''){ ?>
                  <h4 class="mb-md-4 mb-3"><?php echo esc_html(get_theme_mod('vlog_channel_slider_short_heading')); ?></h4>
                <?php }?>
                <a href="<?php the_permalink(); ?>"><h3 class="m-0"><?php the_title(); ?></h3></a>
                <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(),10 )); ?></p>
                <div class="slide-btn mt-md-5 mt-4">
                  <?php if(get_theme_mod('vlog_channel_slider_video_button_url') != ''){ ?>
                    <span class="slide-video-btn">
                      <!-- Button to open the modal -->
                      <a id="openModalButton" data-modal-src="<?php echo esc_url(get_theme_mod('vlog_channel_slider_video_button_url')); ?>" class="video-btn">
                        <?php esc_html_e('Watch Now','vlog-channel') ?></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('vlog_channel_slider_video_button_url') != ''){ ?>
                          <embed id="videoPlayer" height="369" src="<?php echo esc_url(get_theme_mod('vlog_channel_slider_video_button_url')); ?>"  allow="accelerometer; autoplay; classipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></embed>
                          <?php }else{ ?>
                            <h3><?php esc_html_e('Add Video Url In Customizer To Display Video Here','vlog-channel'); ?></h3>
                          <?php } ?>
                        </div>
                      </div> 
                    </span>
                  <?php } ?>
                  <?php if(get_theme_mod('vlog_channel_slider_subscribe_button_url') != ''){ ?>
                    <a href="<?php echo esc_url(get_theme_mod('vlog_channel_slider_subscribe_button_url')); ?>" class="subscribe-btn"><?php esc_html_e('Subscribe','vlog-channel') ?></a>
                  <?php }?>
                </div>
              </div>
            </div>
          <?php $i++; endwhile;
           wp_reset_postdata();?>
          <?php else : ?>
          <div class="no-postfound"></div>
          <?php endif;
          endif;?>
        </div>
      </div>
    </section>
  <?php }?>

  <?php if (get_theme_mod('vlog_channel_event_section_setting', false) != '') { ?>
    <section id="event-section" class="py-5">
      <div class="container">
        <div class="event-head mb-3 py-3">
          <div class="row">
            <div class="col-lg-9 col-md-9 align-self-center">
              <?php if(get_theme_mod('vlog_channel_event_heading') != ''){ ?>
                <h3 class="main-heading text-md-start text-center"><?php echo esc_html(get_theme_mod('vlog_channel_event_heading')); ?></h3>
              <?php }?>
            </div>
            <div class="col-lg-3 col-md-3 align-self-center">
              <?php if(get_theme_mod('vlog_channel_event_btn_text') != '' || get_theme_mod('vlog_channel_event_btn_url') != ''){?>
                <div class="event-btn text-center text-md-end text-center">
                  <a href="<?php echo esc_url(get_theme_mod('vlog_channel_event_btn_url')); ?>"><?php echo esc_html(get_theme_mod('vlog_channel_event_btn_text')); ?><i class="fas fa-arrow-right ms-4"></i></a>
                </div>
              <?php }?>
            </div>
          </div>
        </div>
        <div class="event-outer">
          <?php
            $vlog_channel_event_category = get_theme_mod('vlog_channel_event_category','');
            if($vlog_channel_event_category){
              $vlog_channel_page_query5 = new WP_Query(array( 'category_name' => esc_html($vlog_channel_event_category,'vlog-channel'), 'posts_per_page' => esc_attr(get_theme_mod('vlog_channel_event_number',3))));
              $i=1;
              while( $vlog_channel_page_query5->have_posts() ) : $vlog_channel_page_query5->the_post(); ?>
                <div class="event-box">
                  <div class=" event-img align-self-center ps-0">
                    <?php if(has_post_thumbnail()){
                      the_post_thumbnail();
                      } else{?>
                      <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png"/>
                    <?php } ?>
                    <span class="event-video-btn">
                      <a href="<?php echo esc_url(get_theme_mod('vlog_channel_event_video_button_url'.$i)); ?>" class="video-btn" target="_blank"><i class="far fa-play-circle"></i></a>
                    </span>
                  </div>
                  <div class="event-content">
                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                    <p class="me-lg-5 me-4"><?php echo esc_html( wp_trim_words( get_the_content(),10 )); ?></p>
                    <?php if(get_theme_mod('vlog_channel_event_date'.$i) != ''){?>
                      <p class="event-date"><?php echo esc_html(get_theme_mod('vlog_channel_event_date'.$i)); ?></p>
                    <?php }?>
                  </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(); ?>