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

get_header(); ?>

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

  <?php if( get_theme_mod( 'auction_bidding_slider_hide_show', true) == 1 || get_theme_mod( 'auction_bidding_resp_slider_hide_show', true) == 1) { ?> 
    <section id="slider">
      <?php if(get_theme_mod('auction_bidding_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( 'auction_bidding_slider_speed',4000)) ?>">
        <?php $auction_bidding_pages = array();
          for ( $count = 1; $count <= 3; $count++ ) {
            $mod = intval( get_theme_mod( 'auction_bidding_slider_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $auction_bidding_pages[] = $mod;
            }
          }
          if( !empty($auction_bidding_pages) ) :
            $args = array(
              'post_type' => 'page',
              'post__in' => $auction_bidding_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/banner.png" alt="" />
              <?php } ?>
              <div class="carousel-caption">
                <div class="inner_carousel">
                  <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>
                  <?php
                    $auction_bidding_button_text = get_theme_mod('auction_bidding_slider_button_text', 'Start Exploring');
                    $auction_bidding_button_link = get_theme_mod('auction_bidding_top_button_url', '');
                    if (empty($auction_bidding_button_link)) {
                      $auction_bidding_button_link = get_permalink();
                    }
                    if ($auction_bidding_button_text || !empty($auction_bidding_button_link)) { ?>
                      <div class="slider-btn my-3 my-lg-4 my-md-4 wow slideInRight delay-1000" data-wow-duration="2s">
                        <?php if( get_theme_mod('auction_bidding_slider_button_text') != ''){ ?>
                          <a href="<?php echo esc_url($auction_bidding_button_link); ?>" class="button redmor">
                          <?php echo esc_html($auction_bidding_button_text); ?>
                            <span class="screen-reader-text"><?php echo esc_html($auction_bidding_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('auction_bidding_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('auction_bidding_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('auction_bidding_slider_next_icon','fas fa-angle-right')); ?>"></i></span>
          </a>
          <?php }?>
        </div>
        <?php } else if(get_theme_mod('auction_bidding_slider_type', 'Advance slider') == 'Advance slider'){?>
          <?php echo do_shortcode(get_theme_mod('auction_bidding_advance_slider_shortcode')); ?>
        <?php } ?>
    </section>
  <?php }?>
  <?php do_action( 'auction_bidding_after_slider' ); ?>

  <!-- Product Section -->
 <?php if( get_theme_mod('auction_bidding_services_number') != ''){ ?>
    <section id="main-product" class="wow bounceInRight delay-1000 mt-md-5 mt-3" data-wow-duration="3s"> 
      <div class="container">
        <div class="heding-title">
          <?php if( get_theme_mod('auction_bidding_product_heading_product') != ''){ ?>
            <h2 class="text-center"><?php echo esc_html(get_theme_mod('auction_bidding_product_heading_product'));?></h2>
          <?php }?>
          <p class="text-center"><?php echo esc_html(get_theme_mod('auction_bidding_product_title',''));?></p>
        </div> 
        <div class="tab-section position-relative">
          <div class="tab">
            <?php
              $featured_post = get_theme_mod('auction_bidding_services_number', '');
              for ( $j = 1; $j <= $featured_post; $j++ ){ ?>
              <button class="tablinks" onclick="auction_bidding_services_tab(event, '<?php $main_id = get_theme_mod('auction_bidding_services_text'.$j); $tab_id = str_replace(' ', '-', $main_id); echo $tab_id; ?> ')">
              <?php echo esc_html(get_theme_mod('auction_bidding_services_text'.$j)); ?></button>
            <?php }?>
          </div>
        </div>
        <?php for ( $j = 1; $j <= $featured_post; $j++ ){ ?>
          <div id="<?php $main_id = get_theme_mod('auction_bidding_services_text'.$j); $tab_id = str_replace(' ', '-', $main_id); echo $tab_id; ?>"  class="tabcontent"> 
            <div class="row"> 
              <?php if ( class_exists( 'WooCommerce' )) {?>
                <?php $args = array( 
                  'post_type' => 'product',
                  'product_cat' => get_theme_mod('auction_bidding_product_settings'.$j),
                  'order' => 'ASC',
                  'hide_empty' => 0,
                );
                $loop = new WP_Query( $args );
                  while ( $loop->have_posts() ) : $loop->the_post(); global $product; 
                  
                  $post_id = get_the_ID();
                  $end_date_ = get_post_meta($post_id, 'woo_ua_auction_end_date', true);
                  ?>
                  <div class="col-lg-3 col-md-6 pb-3 pro-sec">
                    <div class="main-product-section position-relative">
                      <p class="the_timer" data-date="<?php echo $end_date_?>"></p>
                      <div class="box">
                        <?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()).'" />'; ?>
                          <div class="box-content">
                            <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>
                            <a class="pro-button" href="<?php the_permalink(); ?>"><?php echo esc_html('Bid Now','auction-bidding');?><span class="screen-reader-text"><?php echo esc_html('Bid Now','auction-bidding');?></span></a>
                          </div>
                        <div class="social-links">
                          <h3><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                        </div>
                      </div>
                    </div>
                  </div>
                <?php endwhile; wp_reset_query(); ?> 
                <?php } ?> 
            </div>
          </div>
        <?php }?> 
      </div> 
    </section>
  <?php }?>
  <?php do_action( 'auction_bidding_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(); ?>