<?php
/**
 * Template Name: Custom Home Page
 */
get_header();

?>
<!-- banner section -->
<main id="maincontent" role="main">

  <?php do_action( 'vw_gift_shop_above_slider' ); ?>
  
  <?php 
    $vw_gift_shop_number = get_theme_mod('vw_gift_shop_slide_number');
    if($vw_gift_shop_number != ''){
  ?>
    <section class="slider-section wow fadeInRightBig" data-wow-delay=".25s">
      <div class="row">
        <div class="col-xl-9 col-lg-9 col-md-12 col-12 p-0 align-self-center slider-content">
          <div id="slider" class="mw-100 m-auto p-0">
            <div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-bs-ride="carousel" data-type="multi" data-interval="false">
              <div class="carousel-inner" role="listbox">
                <?php for ($vw_gift_shop_i=1; $vw_gift_shop_i<=$vw_gift_shop_number; $vw_gift_shop_i++) {?>
                  <div <?php if($vw_gift_shop_i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                    <div class="row">
                      <div class="col-xl-6 col-lg-6 col-md-7 col-12 align-self-center">
                        <div class="carousel-caption">
                          <div class="inner_carousel text-start">
                            <?php if(get_theme_mod('vw_gift_shop_slider_small_text'.$vw_gift_shop_i) != ''){ ?>
                              <p class="small-title mb-3"><?php echo esc_html(get_theme_mod('vw_gift_shop_slider_small_text'.$vw_gift_shop_i)); ?></p>
                            <?php }?>
                            <?php if(get_theme_mod('vw_gift_shop_slider_title'.$vw_gift_shop_i) != ''){ ?>
                              <h1><?php echo esc_html(get_theme_mod('vw_gift_shop_slider_title'.$vw_gift_shop_i)); ?></h1>
                            <?php }?>
                            <?php if(get_theme_mod('vw_gift_shop_slider_text'.$vw_gift_shop_i) != ''){ ?>
                              <p class="slider-text my-2"><?php echo esc_html(get_theme_mod('vw_gift_shop_slider_text'.$vw_gift_shop_i)); ?></p>
                            <?php }?>
                            <?php if( get_theme_mod('vw_gift_shop_slider_button_text'.$vw_gift_shop_i) != '' ){ ?>
                              <div class="read-more text-start">
                                <a href="<?php echo esc_html(get_theme_mod('vw_gift_shop_slider_button_link'.$vw_gift_shop_i)); ?>"><?php echo esc_html( get_theme_mod('vw_gift_shop_slider_button_text'.$vw_gift_shop_i)); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('vw_gift_shop_slider_button_text'.$vw_gift_shop_i)); ?></span></a>
                              </div>
                            <?php } ?>
                          </div>
                        </div>
                      </div>
                      <div class="col-xl-6 col-lg-6 col-md-5 col-12 slider-image text-center align-self-center">
                        <?php if ( get_theme_mod('vw_gift_shop_side_img'.$vw_gift_shop_i) != "" ) {?>
                          <img class="slider-carousel-img" src="<?php echo esc_url(get_theme_mod('vw_gift_shop_side_img'.$vw_gift_shop_i)); ?>" alt="<?php echo esc_attr(get_theme_mod('vw_gift_shop_slide_title'.$vw_gift_shop_i, true)); ?>" title="#slidecaption<?php echo esc_html($vw_gift_shop_i); ?>">
                        <?php } ?>
                      </div>
                    </div>
                  </div>
                <?php } ?>
              </div>
            </div> 
            <div class="clearfix"></div>
          </div>
        </div>
        <?php if ( class_exists( 'WooCommerce' ) ) {
          $vw_gift_shop_selected_product_id = get_theme_mod('vw_gift_shop_slider_product', '');
          if (!empty($vw_gift_shop_selected_product_id)) {
              $vw_gift_shop_args = array(
                  'post_type'      => 'product',
                  'p'              => $vw_gift_shop_selected_product_id,
                  'posts_per_page' => 1,
                  'order'          => 'ASC',
              );
              $vw_gift_shop_loop = new WP_Query($vw_gift_shop_args);
              while ($vw_gift_shop_loop->have_posts()) : $vw_gift_shop_loop->the_post();
                  global $product; ?>
                  <div class="col-xl-3 col-lg-3 col-md-12 col-12 slider-product ps-0">
                      <div class="product-box">
                          <div class="product-box-img">
                              <?php if (has_post_thumbnail($vw_gift_shop_loop->post->ID)) {
                                  echo get_the_post_thumbnail($vw_gift_shop_loop->post->ID, 'shop_catalog');
                              } else {
                                  echo '<img src="' . esc_url(woocommerce_placeholder_img_src()) . '" />';
                              } ?>
                              <div class="product-icons d-flex align-items-center justify-content-center gap-4">
                                <?php if (defined('YITH_WCWL')) { ?>
                                  <?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?>
                                <?php } ?>
                                <?php if ($product->is_type('simple')) {
                                    woocommerce_template_loop_add_to_cart($vw_gift_shop_loop->post, $product);
                                } ?>
                                <?php if ( class_exists( 'YITH_WCQV_Frontend' ) ) {
                                    echo do_shortcode('[yith_quick_view]');
                                } ?>
                              </div>
                          </div>
                          <div class="product-box-content mt-3 text-center">
                              <div class="product-tags">
                                  <?php
                                  $vw_gift_shop_product_tags = wc_get_product_tag_list($product->get_id(), ', ', '<span class="product-tag">', '</span>');
                                  if ($vw_gift_shop_product_tags) {
                                      echo $vw_gift_shop_product_tags;
                                  } ?>
                              </div>
                              <h3><a href="<?php echo esc_url(get_permalink($vw_gift_shop_loop->post->ID)); ?>"><?php the_title(); ?></a></h3>
                              <p class="product-price <?php echo esc_attr(apply_filters('woocommerce_product_price_class', 'price')); ?>">
                                  <?php echo $product->get_price_html(); ?>
                              </p>
                          </div>
                      </div>
                  </div>
              <?php endwhile;
              wp_reset_postdata();
        }} ?>
        <div class="slider-contact-info">
          <div class="row">
            <div class="col-xl-9 col-lg-9 col-md-12 col-12 px-0 py-3 align-self-center slider-contacts">
              <div class="contact-subinfo">
                <div class="row">
                  <div class="col-xl-3 col-lg-3 col-md-4 col-12 align-self-center location-main">
                    <?php if(get_theme_mod('vw_gift_shop_location_icon') != '' || get_theme_mod('vw_gift_shop_location_text') != ''){ ?>
                      <a href="<?php echo esc_url(get_theme_mod('vw_gift_shop_track_locatin_url',false));?>" target="_blank">
                        <p class="location-text mb-0"> <i class="<?php echo esc_attr(get_theme_mod('vw_gift_shop_location_icon','me-2 fa-solid fa-location-dot')); ?>"></i><?php echo esc_html(get_theme_mod('vw_gift_shop_location_text')) ?></p>
                      </a>
                    <?php }?>
                  </div>
                  <div class="col-xl-3 col-lg-3 col-md-3 col-12 align-self-center phone-main">
                    <?php if(get_theme_mod('vw_gift_shop_phone_number') != '' || get_theme_mod('vw_gift_shop_phone_icon') != '' ){ ?>
                      <span class="phone-number"><i class="<?php echo esc_attr(get_theme_mod('vw_gift_shop_phone_icon','fa-solid fa-phone')); ?> me-2"></i><a href="tel:<?php echo esc_attr( get_theme_mod('vw_gift_shop_phone_number','') ); ?>"><?php echo esc_html(get_theme_mod('vw_gift_shop_phone_number',''));?></a></span>
                    <?php }?>
                  </div>
                  <div class="col-xl-3 col-lg-3 col-md-3 col-12 align-self-center d-flex contact-link gap-1">
                    <?php if(get_theme_mod('vw_gift_shop_slider_contact_text') != '' || get_theme_mod('vw_gift_shop_slider_contact_url_text') != ''){ ?>
                      <p class="mb-0"><?php echo esc_html(get_theme_mod('vw_gift_shop_slider_contact_text')); ?>
                      <a href="<?php echo esc_html(get_theme_mod('vw_gift_shop_slider_contact_link')); ?>"><?php echo esc_html( get_theme_mod('vw_gift_shop_slider_contact_url_text')); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('vw_gift_shop_slider_contact_url_text')); ?></span></a></p>
                    <?php }?>
                  </div>
                  <div class="col-xl-3 col-lg-3 col-md-2 col-12 align-self-center d-flex justify-content-center gap-4 slider-main-icons">
                    <?php if( get_theme_mod( 'vw_gift_shop_display_slider_icons', true) == true ) { ?>
                      <a class="carousel-control-prev" data-bs-target="#carouselExampleIndicators" 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('vw_gift_shop_slider_previous_icon','fa-solid fa-angle-left')); ?>" ></i></span>
                        <span class="screen-reader-text"><?php esc_html_e( 'Previous','vw-gift-shop' );?></span>
                      </a>
                      <a class="carousel-control-next" data-bs-target="#carouselExampleIndicators" 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('vw_gift_shop_slider_next_icon','fa-solid fa-angle-right')); ?>" ></i></span>
                        <span class="screen-reader-text"><?php esc_html_e( 'Next','vw-gift-shop' );?></span>
                      </a>  
                    <?php }?>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-xl-3 col-lg-3 col-md-12 col-12 px-0 py-3 align-self-center explore-main text-center">
              <?php if( get_theme_mod('vw_gift_shop_explore_button_text') != '' ){ ?>
                <div class="explore-more text-center">
                  <a href="<?php echo esc_html(get_theme_mod('vw_gift_shop_explore_button_link')); ?>"><?php echo esc_html( get_theme_mod('vw_gift_shop_explore_button_text')); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('vw_gift_shop_explore_button_text')); ?></span></a>
                </div>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </section>
  <?php }?>
  <?php do_action( 'vw_gift_shop_below_slider' ); ?>

  <!-- New Products Section -->
  <?php if (get_theme_mod('vw_gift_shop_new_product_section_hide_show', true)){ ?>
    <section id="product-section" class="pt-5 wow fadeInLeftBig" data-wow-delay=".25s">
      <div class="container">
        <div class="product-sec-content text-center mb-4 pb-1">
          <?php if(get_theme_mod('vw_gift_shop_new_product_section_title') != '') {?>
            <h2 class="section-title"><?php echo esc_html(get_theme_mod('vw_gift_shop_new_product_section_title')) ?></h2>
          <?php }?>
          <?php if(get_theme_mod('vw_gift_shop_new_product_section_text') != '') {?>
            <p class="section-text mb-2"><?php echo esc_html(get_theme_mod('vw_gift_shop_new_product_section_text')) ?></p>
          <?php }?>
        </div>
        <div class="row">
          <?php if ( class_exists( 'WooCommerce' ) ) {
            $vw_gift_shop_selected_category = get_theme_mod('vw_gift_shop_best_product_category', '');
            if (!empty($vw_gift_shop_selected_category)) {
                $vw_gift_shop_args = array( 
                    'post_type'      => 'product',
                    'product_cat'    => $vw_gift_shop_selected_category,
                    'order'          => 'ASC',
                    'hide_empty'     => 0,
                    'posts_per_page' => 4,
                );

                $vw_gift_shop_loop = new WP_Query($vw_gift_shop_args);
                while ($vw_gift_shop_loop->have_posts()) : $vw_gift_shop_loop->the_post(); global $product; ?>
                    <div class="col-xl-3 col-lg-3 col-md-6 col-12">
                        <div class="product-box">
                            <div class="product-box-img">
                                <?php if ( has_post_thumbnail( $vw_gift_shop_loop->post->ID ) ) {
                                    echo get_the_post_thumbnail( $vw_gift_shop_loop->post->ID, 'shop_catalog' );
                                } else {
                                    echo '<img src="'.esc_url(woocommerce_placeholder_img_src()).'" />';
                                } ?>
                                <div class="product-icons d-flex align-items-center justify-content-center gap-4">
                                    <?php if (defined('YITH_WCWL')) { ?>
                                      <?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?>
                                    <?php } ?>
                                    <?php if( $product->is_type( 'simple' ) ){ 
                                        woocommerce_template_loop_add_to_cart( $vw_gift_shop_loop->post, $product ); 
                                    } ?>
                                    <?php if ( class_exists( 'YITH_WCQV_Frontend' ) ) {
                                      echo do_shortcode('[yith_quick_view]');
                                    } ?>
                                </div>
                            </div>
                            <div class="product-box-content mt-3">
                                <div class="product-tags">
                                  <?php 
                                  $vw_gift_shop_product_tags = wc_get_product_tag_list( $product->get_id(), ', ', '<span class="product-tag">', '</span>' );
                                  if ( $vw_gift_shop_product_tags ) {
                                    echo $vw_gift_shop_product_tags;
                                  } ?>
                                </div>
                                <h3><a href="<?php echo esc_url( get_permalink( $vw_gift_shop_loop->post->ID ) ); ?>"><?php the_title(); ?></a></h3>
                                <p class="product-price mb-lg-3 mb-0 d-3 mb-5 <?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>">
                                    <?php echo $product->get_price_html(); ?>
                                </p>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata();
          }} ?>
        </div>
      </div>
    </section>
  <?php }?>
  <?php do_action( 'vw_gift_shop_after_service' ); ?>

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

<?php get_footer(); ?> 