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

get_header(); ?>

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

  <?php if( get_theme_mod( 'wall_decor_wallpaper_slider_hide_show', false) || get_theme_mod( 'wall_decor_wallpaper_resp_slider_hide_show', false) == 1) { ?>
    <section id="slider">
      <?php if(get_theme_mod('wall_decor_wallpaper_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( 'wall_decor_wallpaper_slider_speed',4000)) ?>">
        <?php $wall_decor_wallpaper_pages = array();
          for ( $count = 1; $count <= 3; $count++ ) {
            $mod = intval( get_theme_mod( 'wall_decor_wallpaper_slider_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $wall_decor_wallpaper_pages[] = $mod;
            }
          }
          if( !empty($wall_decor_wallpaper_pages) ) :
            $args = array(
              'post_type' => 'page',
              'post__in' => $wall_decor_wallpaper_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()); ?>/assets/images/slider.png" alt="" />
              <?php } ?>
              <div class="carousel-caption">
                <div class="inner_carousel">
                  <?php if( get_theme_mod('wall_decor_wallpaper_slider_title') != ''){ ?>
                    <p class="new-arrival-slider"><?php echo esc_html(get_theme_mod('wall_decor_wallpaper_slider_title',''));?></p>
                  <?php }?>
                  <h1 class="wow slideInLeft 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 slideInLeft delay-1000" data-wow-duration="2s"><?php $wall_decor_wallpaper_excerpt = get_the_excerpt(); echo esc_html( wall_decor_wallpaper_string_limit_words( $wall_decor_wallpaper_excerpt, 20)); ?></p>
                <div class="slider-btn wow slideInLeft delay-1000" data-wow-duration="2s">
                  <?php 
                    $wall_decor_wallpaper_button_text = get_theme_mod('wall_decor_wallpaper_banner_button_label', 'Shop Now');
                    $wall_decor_wallpaper_button_link = get_theme_mod('wall_decor_wallpaper_top_button_url', ''); 
                    if (empty($wall_decor_wallpaper_button_link)) {
                      $wall_decor_wallpaper_button_link = get_permalink();
                    }
                    if ($wall_decor_wallpaper_button_text || !empty($wall_decor_wallpaper_button_link)) { ?>
                      <div class ="read-more mt-md-4 mt-0">
                        <a href="<?php echo esc_url($wall_decor_wallpaper_button_link); ?>">
                        <?php echo esc_html($wall_decor_wallpaper_button_text); ?>
                          <span class="screen-reader-text"><?php echo esc_html($wall_decor_wallpaper_button_text); ?></span>
                        </a>
                      </div>
                  <?php } ?>
                </div>
                </div>
              </div>
            </div>
          <?php $i++; endwhile; 
          wp_reset_postdata();?>
        </div>
        <?php if( get_theme_mod( 'wall_decor_wallpaper_slider_icon_hide_show', true) == 1) { ?> 
        <div class="social-media">
          <?php if (is_active_sidebar('social-links')) : ?>
            <?php dynamic_sidebar('social-links'); ?>
          <?php else : ?>
            <!-- Default Social Icons Widgets -->
              <div class="widget">
                  <ul class="custom-social-icons" >
                    <li><a href="https://facebook.com" target="_blank"><i class="fab fa-facebook"></i></a></li> 
                    <li><a href="https://twitter.com" target="_blank"><i class="fab fa-twitter"></i></a></li> 
                    <li><a href="https://instagram.com" target="_blank"><i class="fab fa-instagram"></i></a></li> 
                    <li><a href="https://pinterest.com" target="_blank"><i class="fab fa-pinterest"></i></a></li>                     
                  </ul>
              </div>
          <?php endif; ?>  
        </div>
      <?php }?>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
        <?php if(get_theme_mod('wall_decor_wallpaper_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('wall_decor_wallpaper_slider_prev_icon','fas fa-angle-left')); ?>"></i></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('wall_decor_wallpaper_slider_next_icon','fas fa-angle-right')); ?>"></i></span>
          </a>
        <?php }?>
      </div> 
    <?php } else if(get_theme_mod('wall_decor_wallpaper_slider_type', 'Advance slider') == 'Advance slider'){?>
      <?php echo do_shortcode(get_theme_mod('wall_decor_wallpaper_advance_slider_shortcode')); ?>
    <?php } ?>
    </section>
  <?php }?>

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

  <!-- Product Section -->
  <?php if( get_theme_mod( 'wall_decor_wallpaper_product_hide_show',true) != '' && get_theme_mod( 'wall_decor_wallpaper_product_settings') !='') { ?>
    <section id="main-product" class="wow bounceInUp delay-1000 mt-md-5 mt-3" data-wow-duration="3s"> 
      <div class="container">
        <div class="heding-title">
          <?php if( get_theme_mod('wall_decor_wallpaper_product_title') != ''){ ?>
            <p><?php echo esc_html(get_theme_mod('wall_decor_wallpaper_product_title',''));?></p>
          <?php }?>
          <?php if( get_theme_mod('wall_decor_wallpaper_product_heading_product') != ''){ ?>
            <h2 class=""><?php echo esc_html(get_theme_mod('wall_decor_wallpaper_product_heading_product'));?></h2>
          <?php }?>     
        </div>     
          <div class="row"> 
            <?php if ( class_exists( 'WooCommerce' ) && get_theme_mod('wall_decor_wallpaper_product_settings') != '' ) {?>
              <?php $args = array( 
                'post_type' => 'product',
                'product_cat' => get_theme_mod('wall_decor_wallpaper_product_settings'),
                'order' => 'ASC',
                'hide_empty' => 0,
              );
              $loop = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                  <div class="col-lg-3 col-md-6 pt-4 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()).'" />'; ?>
                      <h3><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                      <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></p>
                      <div class="product-arrow">
                        <a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/arrow.png" alt="" />
                        <span class="screen-reader-text"><?php the_title(); ?></span></a>
                      </div>
                    </div>
                </div>
              <?php endwhile; wp_reset_query(); ?> 
              <?php } ?> 
            </div>
        </div>
    </section>
  <?php }?>
<?php do_action( 'wall_decor_wallpaper_after_product_section' ); ?>

  <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(); ?>