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

get_header(); ?>

<main id="maincontent" role="main">
  <?php do_action( 'catering_services_before_slider' ); ?>

  <?php if( get_theme_mod( 'catering_services_slider_hide_show', true) == 1 || get_theme_mod( 'catering_services_resp_slider_hide_show', true) == 1) { ?>
    <section id="slider">
      <?php if(get_theme_mod('catering_services_slider_type', 'Default slider') == 'Default slider' ){ ?>
        <div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel" data-bs-interval="<?php echo esc_attr(get_theme_mod( 'catering_services_slider_speed',4000)) ?>">
          <?php $catering_services_pages = array();
            for ( $count = 1; $count <= 3; $count++ ) {
              $mod = intval( get_theme_mod( 'catering_services_slider_page' . $count ));
              if ( 'page-none-selected' != $mod ) {
                $catering_services_pages[] = $mod;
              }
            }
            if( !empty($catering_services_pages) ) :
              $args = array(
                'post_type' => 'page',
                'post__in' => $catering_services_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_template_directory_uri()); ?>/inc/block-patterns/images/slider.png" alt="" />
                <?php } ?>
                <div class="carousel-caption">
                  <div class="inner_carousel">
                    <h1 class="wow slideInRight delay-1000" data-wow-duration="2s"><a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
                    <p class="wow slideInRight delay-1000" data-wow-duration="2s"><?php $catering_services_excerpt = get_the_excerpt(); echo esc_html( catering_services_string_limit_words( $catering_services_excerpt, esc_attr(get_theme_mod('catering_services_slider_excerpt_number','10')))); ?></p>
                  <?php
                    $catering_services_button_text = get_theme_mod('catering_services_slider_button_text', 'Read More');
                    $catering_services_button_link = get_theme_mod('catering_services_top_button_url', '');
                    if (empty($catering_services_button_link)) {
                      $catering_services_button_link = get_permalink();
                    }
                    if ($catering_services_button_text || !empty($catering_services_button_link)) { ?>
                      <div class="slider-btn wow slideInRight delay-1000" data-wow-duration="2s">
                        <?php if( get_theme_mod('catering_services_slider_button_text', 'Read More' ) != ''){ ?>
                          <a href="<?php echo esc_url($catering_services_button_link); ?>" class="button redmor">
                          <?php echo esc_html($catering_services_button_text); ?>
                            <span class="screen-reader-text"><?php echo esc_html($catering_services_button_text); ?></span>
                          </a>
                        <?php } ?>
                      </div>
                  <?php } ?>

                  </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('catering_services_slider_arrow_hide_show', true)){?>
            <a class="carousel-control-prev" data-bs-target="#carouselExampleInterval" data-bs-slide="prev" role="button">
              <span class="carousel-control-prev-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('catering_services_slider_prev_icon','fas fa-angle-left')); ?>"></i></span>
              <span class="screen-reader-text"><?php esc_html_e( 'Previous','catering-services' );?></span>
            </a>
            <a class="carousel-control-next" data-bs-target="#carouselExampleInterval" data-bs-slide="next" role="button">
              <span class="carousel-control-next-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('catering_services_slider_next_icon','fas fa-angle-right')); ?>"></i></span>
              <span class="screen-reader-text"><?php esc_html_e( 'Next','catering-services' );?></span>
            </a>
          <?php }?> 
        </div>
      <?php } else if(get_theme_mod('catering_services_slider_type', 'Advance slider') == 'Advance slider'){?>
        <?php echo do_shortcode(get_theme_mod('catering_services_advance_slider_shortcode')); ?>
      <?php } ?>
    </section>
  <?php }?>
<?php do_action( 'catering_services_after_slider' ); ?>

<?php if( get_theme_mod( 'catering_services_product_hide_show', true) != '' && get_theme_mod( 'catering_services_popular_dishes_banner_page', true) != '') { ?>
    <section id="product-section" class="product-section pt-lg-5 pt-md-4 pt-4">
      <div class="container">
        <div class="row">
          <div class="col-lg-4 col-md-4 col-12">
            <div class="popular-dishes">
              <?php $catering_services_popular_dishes_page = array();
                for ( $count = 0; $count <= 0; $count++ ) {
                  $mod = absint( get_theme_mod( 'catering_services_popular_dishes_banner_page' ));
                  if ( 'page-none-selected' != $mod ) {
                    $catering_services_popular_dishes_banner_pages[] = $mod;
                  }
                }
                if( !empty($catering_services_popular_dishes_banner_pages) ) :
                  $args = array(
                    'post_type' => 'page',
                    'post__in' => $catering_services_popular_dishes_banner_pages,
                    'orderby' => 'post__in'
                  );
                  $query = new WP_Query( $args );
                  if ( $query->have_posts() ) :
                    $i = 1;
                ?>
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                    <div class="popular-dishes-box" role="listbox">
                      <?php the_post_thumbnail(); ?>
                      <div class="popular-dishes-content">
                        <h2 class="text-md-start text-center wow zoomInDown delay-1000" data-wow-duration="2s"><a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <p class=" mt-md-3 text-md-start text-center wow zoomInDown delay-1000" data-wow-duration="2s"><?php $catering_services_excerpt = get_the_excerpt(); echo esc_html( catering_services_string_limit_words( $catering_services_excerpt, esc_attr(get_theme_mod('catering_services_slider_excerpt_number','20')))); ?></p>
                        <div class="popular-dishes-btn mt-md-3 mt-3 text-md-start text-center">
                          <a href="<?php the_permalink(); ?>"><?php echo esc_html('View All Dishes','catering-services');?><span class="screen-reader-text"><?php echo esc_html('View All Dishes','catering-services');?></span></a>
                        </div>
                      </div>
                    </div>
                <?php $i++; endwhile;
                  wp_reset_postdata();?>
                <?php else : ?>
                  <div class="no-postfound"></div>
                <?php endif;
                endif;?>
            </div>
          </div>
          <div class="col-lg-8 col-md-8 col-12 pt-md-0 pt-5">
            <div class="row">
              <?php if ( class_exists( 'WooCommerce' ) && get_theme_mod('catering_services_popular_dishes_page') != '' ) {?>
                <?php $args = array(
                  'post_type' => 'product',
                  'product_cat' => get_theme_mod('catering_services_popular_dishes_page'),
                  'order' => 'ASC',
                  'hide_empty' => 0,
                );
                $loop = new WP_Query( $args );
                  while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                  <div class="col-lg-6 col-md-6 pt-0 pb-4">
                    <div class="main-product-section">
                      <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(woocommerce_placeholder_img_src()).'" />'; ?>
                          <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></p>
                          <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating ( $loop->post, $product ); } ?>
                          <div class="add-to-cart"><a href="<?php if(function_exists('wc_get_cart_url')){ echo esc_url(wc_get_cart_url()); } ?>" title="<?php esc_attr_e( 'shopping cart','catering-services' ); ?>"><i class='fas fa-shopping-basket'></i></a></div>
                           <h3><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                    </div>
                  </div>
                <?php endwhile; wp_reset_query(); ?>
                <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </section>
  <?php }?>
  <div id="content-vw" class="entry-content py-3">
    <div class="container">
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; // end of the loop. ?>
    </div>
  </div>
</main>

<?php get_footer(); ?>
