<?php
/**
 * Template Name: Custom home page
 */
get_header(); ?>

<main id="maincontent" role="main">
  <?php do_action('food_truck_lite_above_slider_section'); ?>
  
  <?php if(get_theme_mod('food_truck_lite_show_slider') != ''){ ?>
    <section id="slider">
      <div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-bs-ride="carousel"> 
        <?php $food_truck_lite_content_pages = array();
          for ( $count = 1; $count <= 4; $count++ ) {
            $mod = intval( get_theme_mod( 'food_truck_lite_slidersettings_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $food_truck_lite_content_pages[] = $mod;
            }
          }
          if( !empty($food_truck_lite_content_pages) ) :
          $args = array(
            'post_type' => 'page',
            'post__in' => $food_truck_lite_content_pages,
            'orderby' => 'post__in'
          );
          $query = new WP_Query( $args );
          if ( $query->have_posts() ) :
            $i = 1;
        ?>
        <div class="carousel-inner" role="listbox">
          <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
            <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
              <?php if(has_post_thumbnail()){
                  the_post_thumbnail();
              } else{?>
                <img src="<?php echo esc_url(get_theme_file_uri()); ?>/block-patterns/images/banner.png" alt="" />
              <?php } ?>
              <div class="carousel-caption">
                <div class="inner_carousel">
                  <?php if ( get_theme_mod('food_truck_lite_slider_title',true) != '' ) {?>
                    <h1><?php the_title(); ?></h1> 
                  <?php }?>
                  <?php if ( get_theme_mod('food_truck_lite_slider_content',true) != '' ) {?>
                    <p><?php $catering_lite_excerpt = get_the_excerpt(); echo esc_html( food_truck_lite_string_limit_words( $catering_lite_excerpt, esc_attr(get_theme_mod('food_truck_lite_slider_excerpt','25')))); ?></p>
                  <?php }?>
                  <div class="slider-btn">
                    <?php if ( get_theme_mod('food_truck_lite_slider_button_label','READ MORE') != '' && get_theme_mod('food_truck_lite_slider_button',true) != ''|| get_theme_mod('food_truck_lite_slider_button_link') != '') {?>
                      <div class ="read-more mt-md-4 mt-0">
                        <a href="<?php echo esc_url(get_theme_mod('food_truck_lite_slider_button_link')!= '') ? esc_url(get_theme_mod('food_truck_lite_slider_button_link')) : esc_url(get_permalink()); ?>"><?php echo esc_html( get_theme_mod('food_truck_lite_slider_button_label',__('Read More','catering-lite')) ); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('food_truck_lite_slider_button_label',__('Read More','catering-lite')) ); ?></span></a>
                      </div>
                    <?php }?>
                    <?php if ( get_theme_mod('food_truck_lite_slider_button_label2','View More') != '' ) {?>
                      <div class ="read-more mt-md-4 mt-0">
                        <a href="<?php echo esc_url(get_theme_mod('food_truck_lite_slider_button_link2')!= '') ? esc_url(get_theme_mod('food_truck_lite_slider_button_link2')) : esc_url(get_permalink()); ?>"><?php echo esc_html( get_theme_mod('food_truck_lite_slider_button_label2',__('View More','catering-lite')) ); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('food_truck_lite_slider_button_label2',__('View More','catering-lite')) ); ?></span></a>
                      </div>
                    <?php }?>
                  </div>  
                </div>
              </div>
            </div>
          <?php $i++; endwhile; 
          wp_reset_postdata();?>
        </div>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
        <?php if(get_theme_mod('food_truck_lite_slider_arrow_hide_show', true)){?>
          <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('food_truck_lite_slider_prev_icon','fas fa-arrow-left')); ?>"></i></span>
            <span class="screen-reader-text"><?php esc_html_e('Previous','catering-lite'); ?></span>
          </a>
          <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('food_truck_lite_slider_next_icon','fas fa-arrow-right')); ?>"></i></span>
            <span class="screen-reader-text"><?php esc_html_e('Next','catering-lite'); ?></span>
          </a>
        <?php } ?>  
      </div>
      <div class="clearfix"></div>
    </section>
  <?php }?>

  <?php do_action('food_truck_lite_below_slider_section'); ?>
    <?php if(get_theme_mod('catering_lite_menu_section_hide', false)){ ?>
      <section id="menu-section" class="py-5 text-center">
        <div class="container">
          <?php if( get_theme_mod('food_truck_lite_small_title') != ''){ ?>
            <strong><?php echo esc_html(get_theme_mod('food_truck_lite_small_title','')); ?></strong>
          <?php }?>
          <?php $food_truck_lite_content_pages = array();    
          $mod = absint( get_theme_mod( 'food_truck_lite_feature_page' ));
          if ( 'page-none-selected' != $mod ) {
            $food_truck_lite_content_pages[] = $mod;
          }
          if( !empty($food_truck_lite_content_pages) ) :
            $args = array(
              'post_type' => 'page',
              'post__in' => $food_truck_lite_content_pages,
              'orderby' => 'post__in'
            );
            $query = new WP_Query( $args );
            if ( $query->have_posts() ) :
              $count = 0;
              while ( $query->have_posts() ) : $query->the_post(); ?>
                <div class="row box-image text-center">
                  <h2 class="section-title"><?php the_title(); ?></h2>
                  <?php the_content(); ?>
                  <div class="clearfix"></div>
                </div>
              <?php $count++; endwhile; 
              wp_reset_postdata(); ?>
            <?php else : ?>
              <div class="no-postfound"></div>
            <?php endif;
          endif;?>
          <div class="clearfix"></div> 
        </div>
      </section>
    <?php }?>
  <?php do_action('food_truck_lite_after_menu_section'); ?>

  <?php if(get_theme_mod('catering_lite_small_title') != '' || get_theme_mod('catering_lite_section_title') != '' || get_theme_mod('catering_lite_video_post') != '' || get_theme_mod('catering_lite_recipee_category') != '') {?>
    <section id="recipe-section" class="py-5">
      <div class="container">
        <div class="row recipe-sec">
          <div class="col-lg-6 col-md-6 align-self-center">
            <?php
            $catering_lite_postData1 =  get_theme_mod('catering_lite_video_post');
            if($catering_lite_postData1){
              $args = array( 'name' => esc_html($catering_lite_postData1 ,'catering-lite'));
              $query = new WP_Query( $args );
              if ( $query->have_posts() ) :
                while ( $query->have_posts() ) : $query->the_post(); ?>
                  <?php
                    $content = apply_filters( 'the_content', get_the_content() );
                    $video = false;

                    // Only get video from the content if a playlist isn't present.
                    if ( false === strpos( $content, 'wp-playlist-script' ) ) {
                      $video = get_media_embedded_in_content( $content, array( 'video', 'object', 'embed', 'iframe' ) );
                    }
                  ?>
                  <div class="video-box">
                    <?php
                      if ( ! is_single() ) {
                        // If not a single post, highlight the video file.
                        if ( ! empty( $video ) ) {
                          foreach ( $video as $video_html ) {
                            echo '<div class="entry-video">';
                              echo $video_html;
                            echo '</div>';
                          }
                        }
                        elseif(has_post_thumbnail()) { 
                          the_post_thumbnail(); 
                        } 
                      }; 
                    ?>
                  </div>      
                <?php endwhile; 
                wp_reset_postdata();?>
              <?php else : ?>
                <div class="no-postfound"></div>
              <?php
            endif; }?>
          </div>
          <div class="col-lg-6 col-md-6 align-self-center">
            <?php if( get_theme_mod('catering_lite_small_title') != ''){ ?>
              <span class="small-title"><?php echo esc_html(get_theme_mod('catering_lite_small_title')); ?></span>
            <?php }?>
            <?php if( get_theme_mod('catering_lite_section_title') != ''){ ?>
              <h3 class="mb-4"><?php echo esc_html(get_theme_mod('catering_lite_section_title')); ?></h3>
            <?php }?>
            <div class="row"> 
              <?php 
                $catering_lite_catData=  get_theme_mod('catering_lite_recipe_category');
                if($catering_lite_catData){
                  $page_query = new WP_Query(array( 'category_name' => esc_html( $catering_lite_catData ,'catering-lite')));?>
                  <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                    <div class="col-lg-6 col-md-12 align-self-center">
                      <div class="recipe-box mb-4">
                        <div class="row">
                          <?php if(has_post_thumbnail()) { ?>
                            <div class="col-lg-4 col-md-4 col-4 align-self-center">
                              <?php the_post_thumbnail(); ?>
                            </div>
                          <?php } ?>
                          <div class="<?php if(has_post_thumbnail()) { ?>col-lg-8 col-md-8 col-8<?php } else {?>col-lg-12 col-md-12<?php }?> align-self-center">
                            <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                            <span class="entry-author pe-3 d-block"> <?php the_author(); ?></span>
                            <a href="<?php the_permalink(); ?>" class="click-btn"><i class="fas fa-play me-2"></i><span><?php echo esc_html('Click & Watch', 'catering-lite'); ?></span><span class="screen-reader-text"><?php echo esc_html('Click & Watch', 'catering-lite'); ?></span></a>
                          </div>
                        </div>
                      </div>
                    </div>
                  <?php endwhile;
                  wp_reset_postdata();
                }
              ?>
              <?php if (get_theme_mod('catering_lite_viewall_btn_text') != '' || get_theme_mod('catering_lite_viewall_btn_url') != ''){?>
                <div class="view-btn">
                  <a href="<?php echo esc_url(get_theme_mod('catering_lite_viewall_btn_url')); ?>"><?php echo esc_html(get_theme_mod('catering_lite_viewall_btn_text')); ?><span class="screen-reader-text"><?php echo esc_html(get_theme_mod('catering_lite_viewall_btn_text')); ?></span></a>
                </div>
              <?php }?>
            </div>
          </div>
        </div>
        <div class="clearfix"></div> 
      </div>
    </section>
  <?php }?>

  <?php do_action('food_truck_lite_after_menu_section'); ?>

  <div class="container">
    <?php while ( have_posts() ) : the_post(); ?>
      <div class="entry-content"><?php the_content(); ?></div>
    <?php endwhile; // end of the loop. ?>
  </div>
</main>

<?php get_footer(); ?>