<?php
if(get_theme_mod('newarrival_area_disable') != 'on' ){
?>
<?php 
	if( get_theme_mod('newarrival_areaTpadding',true) ) {
		$newarrival_areaTpadding = 'padding-top:'.esc_attr(get_theme_mod('newarrival_areaTpadding')).';';
	}
	if( get_theme_mod('newarrival_areaBpadding',true) ) {
		$newarrival_areaBpadding = 'padding-bottom:'.esc_attr(get_theme_mod('newarrival_areaBpadding')).';';
	}
?>			
<div id="newarrival" class="newarrival-area">		  
	<div class="container">
		<?php
			$showStatic = true;
			for( $i = 1; $i < 11; $i++ ){
				$newarrivalus_page_id = get_theme_mod('newarrivalus_page_icon'.$i); 
				if(!empty($newarrivalus_page_id)){
					$showStatic = false;
					break;
				}
			}
		?>
        <?php
            $newarrival_title = get_theme_mod('newarrival_title', 'New Releases');  
            $newarrival_text = get_theme_mod('newarrival_text', 'Lorem ipsum dolor sit amet,magna aliqua.');
            $newproducttitle = get_theme_mod('newproducttitle', '2009 Trilogy Cuvee Sweet 750ml');
            $newdiscount_text = get_theme_mod('newdiscount_text', '-25%');
            $newbtn_text = get_theme_mod('newbtn_text', 'Shop Now');
			$newbtnlink = get_theme_mod('newbtnlink', '#');
        ?>
        <div class="section-title">  
        	<?php if( $newarrival_title){ ?>                       
              	<h2><?php echo ($newarrival_title);  ?></h2>
            <?php } ?>
            <?php if( $newarrival_text){ ?>
	          	<p><?php echo ($newarrival_text);  ?></p>
	        <?php } ?>
        </div>
        <div class="newarrival-layout"> 
            <div class="row">
            	<div class="col-xl-4 col-lg-4 col-md-4 pr-0">
            		<div class="newproduct-area">
            			<div class="newproduct-box">
            				<div class="newproduct-img">
            					<?php 
									$newproduct_image = get_theme_mod('newproduct_image');
									if(!empty($newproduct_image)){
										echo '<img alt="'. esc_html(get_the_title()) .'" src="'.esc_url($newproduct_image).'" class="img-responsive secondry-bg-img" />';
									}else{
										echo '<img src="'.get_template_directory_uri().'/images/new-arrival.jpg" class="img-responsive" />';
									}
								?>
								<?php if($newdiscount_text ){ ?>		
									<div class="newproduct-disctxt">
										<p>Sale <span><?php echo ($newdiscount_text);  ?></span></p>
									</div>
								<?php }?>
            				</div>
            				<div class="newproduct-content">
            					<?php if($newproducttitle ){ ?>	
            						<h3><?php echo ($newproducttitle);  ?></h3>
            					<?php }?>
            					
            					<div class="abt-btn">
									<?php if($newbtn_text ){ ?>	
										<a href="<?php echo ($newbtnlink);  ?>">
					                    	<?php echo ($newbtn_text);  ?>
										</a>
									<?php }?>
								</div>
            				</div>
            			</div>
            		</div>
            	</div>
				<div class="col-xl-8 col-lg-8 col-md-8 newarrivalus-post-wrap">
					<div class="newarrivalus-post-boxes">
						<div class="owl-carousel">
							<?php
								if(function_exists('woocommerce_template_loop_add_to_cart') && function_exists('WC')){
					    			$args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 4, 'orderby' =>'date','order' => 'DESC' );
					    			$meta_query   = WC()->query->get_meta_query();
					    			$tax_query   = WC()->query->get_tax_query();
					    			
					    			$args = array(
					    				'post_type'   =>  'product',
					    				'stock'       =>  1,
					    				'posts_per_page' => 8, 
					    				'orderby'     =>  'date',
					    				'order'       =>  'DESC',
					    				'meta_query'  =>  $meta_query,
					    				'tax_query'   => $tax_query,
					    			);
					    			$loop = new WP_Query( $args );
					    			if($loop->post_count > 0){
					    				while ( $loop->have_posts() ) : $loop->the_post(); global $product;

									//global $woo_options;
							        //global $post;
							        $terms = get_the_terms( $post->ID, 'product_cat' );
							        foreach ($terms as $term) {
							            $product_cat = $term->name;
							            break;
	       							}
							?>
							<div class="item newarrivalbx " data-wow-duration="1s">			
								<div class="newarrivalus-single" >
									<div class="newarrival-box"> 
										<div class="hi-icon">
											<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
												<?php if (has_post_thumbnail( $loop->post->ID )) 
				    								echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
				    								else
				    									echo '<img src="'.get_template_directory_uri().'/images/default.png" alt="featured products" />'; 
				    							?>
											</a>
											<div class="newarrival-icons">
												<div class="newarrival-list tooltip-container">
													<?php 
														$user_id = get_current_user_id();
														$product_id = $product->get_id();
														$wishlist = get_user_meta($user_id, 'wishlist', true);
														$button_class = in_array($product_id, (array)$wishlist) ? 'added' : '';
														$nonce = wp_create_nonce('update_wishlist_' . $product_id);

														$wishlist_url = esc_url(add_query_arg(
														    array(
														        'update_wishlist' => $product_id,
														        '_wpnonce' => $nonce
														    )
														));

														echo '<a href="' . $wishlist_url . '" class="add-to-wishlist-button ' . $button_class . '">
														    <span class="spinner"></span>
														    <i class="fa fa-heart' . ($button_class ? '' : '-o') . '" aria-hidden="true"></i>
														    <span class="tooltip-text">' . ($button_class ? 'Added to Wishlist' : 'Add to Wishlist') . '</span>
														</a>'; 
													?>
												</div>
											    <div class="newarrival-list tooltip-container">
											        <a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" data-quantity="1" class="button product_type_<?php echo esc_attr( $product->get_type() ); ?> add_to_cart_button">
											            <span class="spinner"></span><i class="fa fa-shopping-cart"></i><span class="tooltip-text">Add to Cart</span>
											        </a>
											    </div>
											    <div class="newarrival-list tooltip-container">
											        <a href="#quick-view-<?php the_id(); ?>" class="quick-view" data-product-id="<?php echo esc_attr( $product->get_id() ); ?>">
											            <span class="spinner"></span><i class="fa fa-eye"></i><span class="tooltip-text">Quick View</span>
											        </a>
											    </div>
											</div>
										</div>
									</div> 
									<div class="newarrival-area-data">
										<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
												<h4 class="inner-area-title"><?php the_title();?></h4>
										</a>
										<div class="price"><?php echo $product->get_price_html(); ?></div>
									</div>				 
								</div>
							</div>
						<?php					
						endwhile; 
							}
							else{
						?>
			<!-- 	<div class="item  newarrivalbx wow zoomIn" data-wow-duration="1s">
					<div class="newarrivalus-single" >
						<div class="newarrival-box"> 
							<div class="hi-icon">
								<a href="#">
									<img class="img-responsive" src="</?php echo esc_url(get_template_directory_uri().'/images/cat2.jpg');?>" alt="featured products" />
									<div class="skewd"></div>	
								</a>
							</div>
						</div> 
						<div class="newarrival-area-data">
							<a href="#"><h4 class="inner-area-title">Wooden Mirror</h4></a>
							<div class="price">$159.00</div>
							<div class="fea-btn">
								<a href="#">
									<span>Add To Cart</span>
									<span><i class="fa fa-shopping-cart" aria-hidden="true"></i></span>
								</a>
							</div>
						</div>				 
					</div>
				</div> -->
				<?php }
					//wp_reset_query(); 
				}
					?>
				<!-- </div>	 -->
				</div>
				<div class="newarrival-overlay"></div>
			</div>
		</div>
		</div>
	  </div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
          $('.newarrival-area .owl-carousel').owlCarousel({
            refreshClass: 'owl-refresh',
            autoplayTimeout:7000,
            loop: true,
            margin: 30,
            autoHeight: true,
            autoWidth: false,
            autoplay: false,
            // animateOut: 'lightSpeedOut',
            // animateOut: 'slideOutDown',
            animateOut: 'fadeOutRight',
            animateIn: 'fadeInLeft',
            navText: [
                    '<i class="fa fa-caret-left"></i> ',
                    '<i class="fa fa-caret-right"></i>'
                ],
            responsiveClass: true,

            responsive: {
              0: {
                items: 1,
                nav: true,
                margin: 40
              },
              450: {
                items:2,
                nav: true,
                margin: 20
              },
              992: {
                items:3,
                nav: true,
                loop: true,
                margin: 20
              }
            }
          })
        })
</script>
<?php }  