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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider" class="slider-box">
    <div class="row">
      <div class="col-lg-5 col-md-5 col-sm-12 col-12 pl-0 small-img align-self-center">
        <?php if ( get_theme_mod('curtains_fabric_slider_small_image') != "" ) {?>
          <img class="small-img" src="<?php echo esc_url(get_theme_mod('curtains_fabric_slider_small_image')); ?>" alt="small image">
        <?php }?>
      </div>
      <div class="col-lg-7 col-md-7 col-sm-12 col-12">
        <div class="slider-inner-box">
          <?php if(get_theme_mod('curtains_fabric_slider_main_text') != ''){ ?>
            <h3 class="mb-2"><?php echo esc_html(get_theme_mod('curtains_fabric_slider_main_text','')); ?></h3>
          <?php }?>
          <?php if(get_theme_mod('curtains_fabric_slider_main_heading') != ''){ ?>
            <h2 class="mb-2"><?php echo esc_html(get_theme_mod('curtains_fabric_slider_main_heading','')); ?></h2>
          <?php }?>
          <?php if(get_theme_mod('curtains_fabric_slider_button_text_url') != '' || get_theme_mod('curtains_fabric_slider_button_text') != ''){ ?>
            <div class="slide-btn mt-5"><a href="<?php echo esc_url(get_theme_mod('curtains_fabric_slider_button_text_url','')); ?>"><?php echo esc_html(get_theme_mod('curtains_fabric_slider_button_text','')); ?></a></div>
          <?php }?>
        </div>
      </div>
    </div>
    <div id="slider-post">
      <div class="owl-carousel" role="listbox">
        <?php
          $curtains_fabric_services_cat = get_theme_mod('curtains_fabric_services_sec_category','');
          if($curtains_fabric_services_cat){
            $curtains_fabric_page_query5 = new WP_Query(array( 'category_name' => esc_html($curtains_fabric_services_cat,'curtains-fabric')));
            $i=1;
            while( $curtains_fabric_page_query5->have_posts() ) : $curtains_fabric_page_query5->the_post(); ?>
              <div class="row post-box">
                <div class="col-lg-5 col-md-5 col-sm-6 col-12 pr-0 align-self-center">
                  <div class=" ser-content text-start">
                    <?php if( get_post_meta($post->ID, 'curtains_fabric_text_1', true) ) {?>
                     <h5 class="text p-0 mb-2"><?php echo esc_html(get_post_meta($post->ID,'curtains_fabric_text_1',true)); ?></h5>
                    <?php }?>
                    <h4 class="mb-1"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                    <p class="m-0"><?php echo esc_html( wp_trim_words( get_the_content(), esc_attr(get_theme_mod('curtains_fabric_slider_excerpt_length', 15)) )); ?></p>
                    <div class="post-btn mt-2"><a href="<?php the_permalink(); ?>"><?php esc_html_e('Shop Now','curtains-fabric'); ?></a></div>
                  </div>
                </div>
                <div class="col-lg-7 col-md-7 col-sm-6 col-12 pl-0 post-img align-self-center">
                  <div class="featured-img text-center">
                    <?php if(has_post_thumbnail()){ ?><img src="<?php the_post_thumbnail_url('full'); ?>"/><?php }else { ?><div class="post-bg"></div> <?php } ?>
                  </div>
                </div>
              </div>
            <?php $i++; endwhile;
          wp_reset_postdata();
        } ?>
      </div>
    </div>
    <div class="social-link">
      <?php if(get_theme_mod('curtains_fabric_facebook_url') != ''){ ?>
        <a href="<?php echo esc_url(get_theme_mod('curtains_fabric_facebook_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('curtains_fabric_facebook_icon') ); ?>"></i></a>
      <?php }?>
      <?php if(get_theme_mod('curtains_fabric_twitter_url') != ''){ ?>
        <a href="<?php echo esc_url(get_theme_mod('curtains_fabric_twitter_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('curtains_fabric_twitter_icon') ); ?>"></i></a>
      <?php }?>
      <?php if(get_theme_mod('curtains_fabric_intagram_url') != ''){ ?>
        <a href="<?php echo esc_url(get_theme_mod('curtains_fabric_intagram_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('curtains_fabric_intagram_icon') ); ?>"></i></a>
      <?php }?>
      <?php if(get_theme_mod('curtains_fabric_linkedin_url') != ''){ ?>
        <a href="<?php echo esc_url(get_theme_mod('curtains_fabric_linkedin_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('curtains_fabric_linkedin_icon') ); ?>"></i></a>
      <?php }?>
      <?php if(get_theme_mod('curtains_fabric_pintrest_url') != ''){ ?>
        <a href="<?php echo esc_url(get_theme_mod('curtains_fabric_pintrest_url','')); ?>"><i class="<?php echo esc_attr( get_theme_mod('curtains_fabric_pintrest_icon') ); ?>"></i></a>
      <?php }?>
    </div>
  </section>
  <section class="product-sec py-5 ">
    <div class="container">
      <div class=" text-center headings">
        <?php if(get_theme_mod('curtains_fabric_product_main_heading') != ''){ ?>
          <h3 class="mb-2"><?php echo esc_html(get_theme_mod('curtains_fabric_product_main_heading','')); ?></h3>
        <?php }?>
        <?php if(get_theme_mod('curtains_fabric_product_main_discription') != ''){ ?>
          <p><?php echo esc_html(get_theme_mod('curtains_fabric_product_main_discription','')); ?></p>
        <?php }?>
      </div>
      <div class="owl-carousel product-home-box">
        <?php
        if ( class_exists( 'WooCommerce' ) ) {
          $curtains_fabric_args = array(
            'post_type' => 'product',
            'posts_per_page' => get_theme_mod('curtains_fabric_home_product_per_page', 4),
            'product_cat' => get_theme_mod('curtains_fabric_home_product'),
            'order' => 'ASC'
          );
          $loop = new WP_Query( $curtains_fabric_args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <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(wc_placeholder_img_src()).'" />'; ?></a>
              </div>
              <div class="product-content text-start pt-3">
                <div class="rating">
                  <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
                </div>
                <h3 class="m-0"><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' ) ); ?> m-0"><?php echo $product->get_price_html(); ?></p>
              </div>
            </div>
          <?php endwhile; wp_reset_postdata(); ?>
        <?php } ?>
      </div>
    </div>
  </section>
  <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(); ?>