<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Classic Woocommerce
 */

get_header(); ?>

<div id="content">
  <section id="slider" class="py-1">
    <div class="container">
      <div class="row">
      <div class="col-lg-3 col-md-4 col-sm-12 col-12">
        <div class="categories-box border border-solid">
          <h5 class="mb-0 text-start d-flex align-items-center w-100 py-3 px-3 text-white border border-0" style="background-color: #302e3c;">
          <svg class="icon-l" width="26" height="26" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"></path></svg>
          Categories
          </h5>
          <ul class="p-2 px-3 m-0 categories-list primary-bg-color">
            <?php if(class_exists('woocommerce')){ ?>
              <?php
                $classic_ecommerce_args = array(
                  'number'     => get_theme_mod('classic_ecommerce_product_category_number'),
                  'orderby'    => 'title',
                  'order'      => 'ASC',
                  'hide_empty' => 0,
                  'parent'  => 0
                );
                $product_categories = get_terms( 'product_cat', $classic_ecommerce_args );
                $classic_ecommerce_count = count($product_categories);
                if ( $classic_ecommerce_count > 0 ){
                  foreach ( $product_categories as $classic_ecommerce_product_category ) {
                    $classic_ecommerce_cat_id   = $classic_ecommerce_product_category->term_id;
                    $classic_ecommerce_cat_link = get_category_link( $classic_ecommerce_cat_id );
                    if ($classic_ecommerce_product_category->category_parent == 0) { ?>
                  <li class="d-flex text-white align-items-center"><i class="fa fa-caret-right fs-5 text-white" aria-hidden="true"></i> <a href="<?php echo esc_url(get_term_link( $classic_ecommerce_product_category ) ); ?>">
                  <?php
                }
                  echo esc_html( $classic_ecommerce_product_category->name ); ?>n</a></li>
                  <?php
                  }
                }
              ?>
            <?php }?>
          </ul>
        </div>
      </div>
        <div class="col-lg-9 col-md-8 col-sm-12 col-12 px-0">
          <div class="catwrapslider">
        <div class="owl-carousel">
          <?php if( get_theme_mod('classic_ecommerce_hide_categorysec',true) ) { ?>
          <?php $classic_ecommerce_queryvar = new WP_Query('cat='.esc_attr(get_theme_mod('classic_ecommerce_slidersection',false)));
            while( $classic_ecommerce_queryvar->have_posts() ) : $classic_ecommerce_queryvar->the_post(); ?>
              <div class="slidesection"> 
                <?php if(has_post_thumbnail()){
                  the_post_thumbnail('full');
                  } else{?>
                  <img src="<?php echo esc_url(get_theme_file_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'classic-woocommerce'); ?>"/>
                <?php } ?>
                <div class="slider-box">
                  <h1><a href="<?php echo esc_url( get_permalink() );?>"><?php the_title(); ?></a></h1>
                  <?php
                    $trimexcerpt = get_the_excerpt();
                    $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 20 );
                    echo '<p>' . esc_html( $shortexcerpt ) . '</p>'; 
                  ?>
                  <div class="shop-now">
                    <?php 
                    $classic_ecommerce_button_text = get_theme_mod('classic_ecommerce_button_text', 'SHOP NOW');
                    $classic_ecommerce_button_link_slider = get_theme_mod('classic_ecommerce_button_link_slider', ''); 
                    if (empty($classic_ecommerce_button_link_slider)) {
                        $classic_ecommerce_button_link_slider = get_permalink();
                    }
                    if ($classic_ecommerce_button_text || !empty($classic_ecommerce_button_link_slider)) { ?>
                      <?php if(get_theme_mod('classic_ecommerce_button_text', 'SHOP NOW') != ''){ ?>
                        <a href="<?php echo esc_url($classic_ecommerce_button_link_slider); ?>">
                          <?php echo esc_html($classic_ecommerce_button_text); ?>
                            <span class="screen-reader-text"><?php echo esc_html($classic_ecommerce_button_text); ?></span>
                        </a>
                      <?php } ?>
                    <?php } ?>
                  </div>
                </div>
              </div>
            <?php endwhile; wp_reset_postdata(); ?>
          <?php } ?>
        </div>
      </div>
        </div>

      </div>

    </div>

    <div class="clear"></div>
  </section>

  <?php
    $classic_ecommerce_hidcatproduct = get_theme_mod('classic_ecommerce_hidcatproduct', true);

    if ($classic_ecommerce_hidcatproduct != "") { ?>
    <section id="content-creation">
      <div class="container">
        <div id="recent-product">
          <?php if ( get_theme_mod('classic_ecommerce_recent_product_title') != "") { ?>
            <h2><?php echo esc_html(get_theme_mod('classic_ecommerce_recent_product_title','')); ?></h2>
          <?php } ?>
        </div>

        <?php while ( have_posts() ) : the_post(); ?>
          <?php the_content(); ?>
        <?php endwhile; // end of the loop. ?>
      </div>
    </section>
  <?php } ?>

</div>

<?php get_footer(); ?>
