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

get_header(); ?>

<main id="skip-content">
<?php if (get_theme_mod('skin_care_products_slider_section_setting', true) != '') { ?>
  <section id="top-slider">
    <div class="social-link">
      <?php if(get_theme_mod('skin_care_products_facebook_url') != ''){ ?>
          <a href="<?php echo esc_url(get_theme_mod('skin_care_products_facebook_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('skin_care_products_facebook_icon') ); ?>"></i></a>
        <?php }?>
        <?php if(get_theme_mod('skin_care_products_twitter_url') != ''){ ?>
          <a href="<?php echo esc_url(get_theme_mod('skin_care_products_twitter_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('skin_care_products_twitter_icon') ); ?>"></i></a>
      <?php }?>
        <?php if(get_theme_mod('skin_care_products_intagram_url') != ''){ ?>
          <a href="<?php echo esc_url(get_theme_mod('skin_care_products_intagram_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('skin_care_products_intagram_icon') ); ?>"></i></a>
        <?php }?>
        <?php if(get_theme_mod('skin_care_products_linkedin_url') != ''){ ?>
          <a href="<?php echo esc_url(get_theme_mod('skin_care_products_linkedin_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('skin_care_products_linkedin_icon') ); ?>"></i></a>
        <?php }?>
        <?php if(get_theme_mod('skin_care_products_pintrest_url') != ''){ ?>
          <a href="<?php echo esc_url(get_theme_mod('skin_care_products_pintrest_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('skin_care_products_pintrest_icon') ); ?>"></i></a>
        <?php }?>
    </div>
    <?php $skin_care_products_slide_pages = array();
      for ( $skin_care_products_count = 1; $skin_care_products_count <= 3; $skin_care_products_count++ ) {
        $skin_care_products_mod = intval( get_theme_mod( 'skin_care_products_top_slider_page' . $skin_care_products_count ));
        if ( 'page-none-selected' != $skin_care_products_mod ) {
          $skin_care_products_slide_pages[] = $skin_care_products_mod;
        }
      }
      if( !empty($skin_care_products_slide_pages) ) :
        $skin_care_products_args = array(
          'post_type' => 'page',
          'post__in' => $skin_care_products_slide_pages,
          'orderby' => 'post__in'
        );
        $skin_care_products_query = new WP_Query( $skin_care_products_args );
        if ( $skin_care_products_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $skin_care_products_query->have_posts() ) : $skin_care_products_query->the_post(); ?>
        <div class="slide-box">
          <div class="slider-image">
            <?php if(has_post_thumbnail()){
              the_post_thumbnail();
              } else{?>
              <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
            <?php } ?>
          </div>
          <div class="slider-inner-box">
            <?php if(get_theme_mod('skin_care_products_slider_short_heading') != ''){ ?>
              <h5 class="main-heading mb-4"><?php echo esc_html(get_theme_mod('skin_care_products_slider_short_heading')); ?></h5>
            <?php }?>
            <h3 class="m-0 mb-4 pb-3"><?php the_title(); ?></h3>
            <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(),esc_attr(get_theme_mod('skin_care_products_slider_excerpt_length', 70)) )); ?><p>
            <div class="slide-btn mt-4">
              <a href="<?php the_permalink(); ?>"><?php esc_html_e('Shop Now','skin-care-products'); ?></a>
            </div>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
  </section>
<?php }?>

<?php if (get_theme_mod('skin_care_products_activities_section_setting', true) != '') { ?>
  <section class="featured py-5">
    <div class="container ">
      <div class="row">
        <div class="col-lg-4 col-md-5 col-sm-12 col-12 align-self-center">
          <div class="heading text-start mb-4">
            <?php if(get_theme_mod('skin_care_products_services_short_heading') != ''){ ?>
              <h4 class="main-heading mb-3"><?php echo esc_html(get_theme_mod('skin_care_products_services_short_heading')); ?></h4>
            <?php }?>
            <?php if(get_theme_mod('skin_care_products_services_heading') != ''){ ?>
              <h3 class="main-heading"><?php echo esc_html(get_theme_mod('skin_care_products_services_heading')); ?></h3>
            <?php }?>
            <?php if(get_theme_mod('skin_care_products_services_content') != ''){ ?>
              <p class="main-content"><?php echo esc_html(get_theme_mod('skin_care_products_services_content')); ?></p>
            <?php }?>
            <?php if(get_theme_mod('skin_care_products_clock_timer_end') != ''){ ?>
              <div class="countdowntimer text-center mt-2">
                <p id="timer" class="countdown">
                  <?php 
                  $skin_care_products_dateday = get_theme_mod('skin_care_products_clock_timer_end','12 May 2025'); ?>
                  <input type="hidden" class="date" value="<?php echo esc_html($skin_care_products_dateday); ?>"></p>
              </div>
            <?php }?>
            <?php if(get_theme_mod('skin_care_products_product_btn_url') != '' || get_theme_mod('skin_care_products_product_btn_text') != ''){ ?>
              <a class="product-btn" href="<?php echo esc_url(get_theme_mod('skin_care_products_product_btn_url')); ?>"><?php echo esc_html(get_theme_mod('skin_care_products_product_btn_text')); ?></a>
            <?php }?>
          </div>
        </div>
        <div class="col-lg-8 col-md-7 col-sm-12 col-12 align-self-center">
          <div class="owl-carousel product-home-box">
            <?php
            if ( class_exists( 'WooCommerce' ) ) {
              $skin_care_products_args = array(
                'post_type' => 'product',
                'posts_per_page' => 6,
                'product_cat' => get_theme_mod('skin_care_products_home_product'),
                'order' => 'ASC'
              );
              $loop = new WP_Query( $skin_care_products_args );
              while ( $loop->have_posts() ) : $loop->the_post(); global $product; 
                $product_cats = wc_get_product_category_list( $product->get_id(), ', ', '<span class="woo-cat">', '</span>' );
                $product_cats_array = explode( ', ', strip_tags( $product_cats ) );
                ?>
                <div class="products-box">
                  <div class="product-image">
                    <a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"> <?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()).'" />'; ?></a>
                  </div>
                  <div class="product-content pt-3 text-start">
                    <?php 
                    if ( ! empty( $product_cats_array ) ) { ?>
                      <span class="woo-cat"><?php echo $product_cats_array[0]; ?></span>
                    <?php } ?>
                    <h3 class="mb-2"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                    <div class="row">
                      <div class="col-xl-5 col-lg-6 col-md-4 col-sm-5 col-6 align-self-center">
                        <div class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> m-0"><?php echo $product->get_price_html(); ?></div>
                      </div>
                      <div class="col-xl-7 col-lg-6 col-md-8 col-sm-7 col-6 align-self-center text-end">
                        <div class="cart-btn"><?php if( $product->is_type( 'simple' ) ) { woocommerce_template_loop_add_to_cart(  $loop->post, $product );} ?> <i class="fas fa-arrow-right ms-2"></i></div>
                      </div>
                    </div>
                  </div>
                </div>
              <?php endwhile; wp_reset_postdata(); ?>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
  </section>
<?php }?>
  <section id="page-content">
    <div class="container">
      <div class="py-5">
        <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              the_content();
            endwhile;
          endif;
        ?>
      </div>
    </div>
  </section>
</main>

<?php get_footer(); ?>