<?php 
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! function_exists( 'ecommerce_comp_mega_mart_product_one' ) ) :
function ecommerce_comp_mega_mart_product_one() {
$product_one_hs			= get_theme_mod('product_one_hs', '1');	
$product_one_title			= get_theme_mod('product_one_title',__('Hot Deal :','ecommerce-companion'));	
$product_one_heading_text	= get_theme_mod('product_one_heading_text',__('Don\'t Miss Out! Grab the Best Deals Before They\'re Gone!','ecommerce-companion'));	
$product_one_button_title	= get_theme_mod('product_one_button_title',__('Wrap Coupon ?','ecommerce-companion'));
$product_one_button_link	= get_theme_mod('product_one_button_link','');
$product_one_newtab			= get_theme_mod('product_one_newtab','yes');
$product_one_nofollow		= get_theme_mod('product_one_nofollow','yes');
$product_one_section_title	= get_theme_mod('product_one_section_title',__('Vegetable Products','ecommerce-companion'));

$product_one_banner_one_title	= get_theme_mod('product_one_banner_one_title',__('30% OFF ','ecommerce-companion'));	
$product_one_banner_one_text	= get_theme_mod('product_one_banner_one_text',__('Everyday Fresh Fruits From South Africa','ecommerce-companion'));	
$product_one_banner_one_img	= get_theme_mod('product_one_banner_one_img', ECOMMERCE_COMP_PLUGIN_URL .'inc/themes/mega-mart/assets/images/product/one/banner1.png');

$product_one_banner_two_title	= get_theme_mod('product_one_banner_two_title',__('100% Fresh ','ecommerce-companion'));	
$product_one_banner_two_text	= get_theme_mod('product_one_banner_two_text',__('Tasty Steaks From  Our Best Chief','ecommerce-companion'));	
$product_one_banner_two_img	= get_theme_mod('product_one_banner_two_img', ECOMMERCE_COMP_PLUGIN_URL .'inc/themes/mega-mart/assets/images/product/one/banner2.png');
$product_one_hs_tab			= get_theme_mod('product_one_hs_tab','1'); 
$product_one_cat			= get_theme_mod('product_one_cat');

$product_one_date			= get_theme_mod('product_one_date','2026-01-01');	
$product_one_time			= get_theme_mod('product_one_time','04:36');
if( $product_one_hs == '1' ):
?>
<?php 
	if ( class_exists( 'woocommerce' ) ) {
	$args                   = array(
		'post_type' => 'product',
		'posts_per_page' => -1,
	);
	
	/* phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Small posts_per_page, safe usage */
	$args['tax_query'] = array(
		array(
			'taxonomy' => 'product_cat',
			'field' => 'slug',
			'terms' => $product_one_cat,
		),
	);
?>
<section id="product-one-section" class="product-section st-py-default mt-lg-0 mt-sm-3 mt-2 product-one-home">
	<div class="container">
		<div class="row">
			<div class="col-lg-12 col-12 mb-sm-4 mb-2 wow fadeInUp">
				<div class="heading-default">
					<?php if( !empty($product_one_title)): ?>
					<div class="title">
						<h5><?php echo esc_html($product_one_title); ?></h5>
					</div>
					<?php endif; ?>
					<?php if( !empty($product_one_heading_text)): ?>
					<div class="heading-text">
						<p><?php echo esc_html($product_one_heading_text); ?></p>
					</div>
					<?php endif; ?>
					<div class="heading-right">
						<div data-timer="<?php echo esc_attr($product_one_date.' '.$product_one_time); ?>" id="dealsofdayCountDown" class="dealsofday-timer timer-container">
							<div class="dealsofday-item">
								<div class="dealsofday-count">
									<h6 class="days">05</h6>
								</div>
								<p><?php echo esc_html('DAY','ecommerce-companion'); ?></p>
							</div>
							<div class="dealsofday-item">
								<div class="dealsofday-count">
									<h6 class="hours">15</h6>
								</div>
								<p><?php echo esc_html('HRS','ecommerce-companion'); ?></p>
							</div>
							<div class="dealsofday-item">
								<div class="dealsofday-count">
									<h6 class="minutes">55</h6>
								</div>
								<p><?php echo esc_html('MIN','ecommerce-companion'); ?></p>
							</div>
							<div class="dealsofday-item">
								<div class="dealsofday-count">
									<h6 class="seconds">20</h6>
								</div>
								<p><?php echo esc_html('SEC','ecommerce-companion'); ?></p>
							</div>
						</div>	
					<?php if( !empty($product_one_button_title)): ?>						
						<a href="<?php echo esc_url($product_one_button_link); ?>" class="btn" <?php if($product_one_newtab =='yes') {echo 'target="_blank"'; } ?> rel="<?php if($product_one_newtab =='yes') {echo 'noreferrer noopener';} ?> <?php if($product_one_nofollow =='yes') {echo 'nofollow';} ?>"><i class="fa fa-gift"></i> <?php echo esc_html($product_one_button_title); ?></a>
					<?php endif; ?>
					</div>
				</div>
			</div>
			<div class="col-lg-12 col-12">
				<div class="row">
					<div class="col-8 col-lg-3 wow fadeInUp" data-wow-delay="0ms" data-wow-duration="1500ms">
					<?php if( !empty($product_one_section_title)): ?>
						<div class="section-title"><?php echo esc_html($product_one_section_title); ?></div>
					<?php endif; ?>
					</div>
					<?php if($product_one_hs_tab=='1' && !empty($product_one_cat)): 
					$count = count($product_one_cat);
					if ( $count > 0 ){
					?>
					<div class="col-4 col-lg-9 d-flex justify-content-end align-items-center wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
						<div class="product-filter-wraper">
							<div id="feature" class="tab-filter">								
								<?php foreach ( $product_one_cat as $i=> $product_category ) { 
								$product_cat_name = get_term_by( 'slug', $product_category, 'product_cat' );
								?>
							<?php if($i == '0'){  ?>
								<a href="javascript:void(0);" data-filter="<?php echo 'product_cat-'.esc_attr($product_category); ?>" class="active" rel="nofollow noopner noreferrer"><?php  echo esc_html($product_cat_name->name); ?></a>
							
							<?php }else{ ?>		
								<a href="javascript:void(0);" data-filter="<?php echo 'product_cat-'.esc_attr($product_category); ?>" rel="nofollow noopner noreferrer"><?php  echo esc_html($product_cat_name->name); ?></a>
								<?php }} ?>
							</div>
						</div>
						<div class="custom-owl-nav">
							<button type="button" class="custom-prev"><i class='fa fa-chevron-left'></i></button>
							<button type="button" class="custom-next"><i class='fa fa-chevron-right'></i></button>
						</div>
					</div>
					<?php } endif; ?>
				</div>
				<div class="row banner-section gx-0">
					<div class="col-6">
						<aside class="banner-item bg-3 wow fadeInUp lehr_effect" data-wow-delay="0ms" data-wow-duration="1500ms">
						<?php if( !empty($product_one_banner_one_title) || !empty($product_one_banner_one_text) ): ?>
							<div class="banner-content">
								<span class="secondary-color2"><?php echo esc_html($product_one_banner_one_title); ?></span>
								<h4><?php echo esc_html($product_one_banner_one_text); ?></h4>
							</div>
						<?php endif; ?>
						<?php if( !empty($product_one_banner_one_img)): ?>
							<div class="banner-img">
								<img src="<?php echo esc_url($product_one_banner_one_img); ?>" alt="<?php echo esc_attr($product_one_banner_one_title); ?>">
							</div>               
						<?php endif; ?>
						</aside>
					</div>
					<div class="col-6">
						<aside class="banner-item bg-4 wow fadeInUp lehr_effect" data-wow-delay="200ms" data-wow-duration="1500ms">
							<?php if( !empty($product_one_banner_two_title) || !empty($product_one_banner_two_text) ): ?>
							<div class="banner-content">
								<span class="secondary-color"><?php echo esc_html($product_one_banner_two_title); ?></span>
								<h4><?php echo esc_html($product_one_banner_two_text); ?></h4>
							</div>
						<?php endif; ?>
						<?php if( !empty($product_one_banner_two_img)): ?>
							<div class="banner-img">
								<img src="<?php echo esc_url($product_one_banner_two_img); ?>" alt="<?php echo esc_attr($product_one_banner_two_title); ?>">
							</div>               
						<?php endif; ?>               
						</aside>
					</div>
				</div>
			</div>
			<div class="col-lg-12 col-12 wow fadeInUp">
				<ul id="product-filter-init" class="products columns-3 grid product-filter-init products-slider owl-carousel owl-theme">
				<?php
					$loop = new WP_Query( $args );
					while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
					<?php
					$terms = get_the_terms( $loop->ID, 'product_cat' );
										
					if ( $terms && ! is_wp_error( $terms ) ) : 
						$links = array();

						foreach ( $terms as $term ) 
						{
							$links[] = $term->slug;
						}
						
						$tax = join( '","', $links );		
					else :	
						$tax = '';	
					endif;
				?>
					<?php get_template_part('woocommerce/content','product'); ?>					
					<?php endwhile; ?>
					<?php  wp_reset_postdata(); ?>
				</ul>
			</div>
		</div>
	</div>
</section>
<?php } endif; } endif; ?>
<?php
if ( function_exists( 'ecommerce_comp_mega_mart_product_one' ) ) {
$ecommerce_companion_section_priority = apply_filters( 'mega_mart_section_priority', 15, 'ecommerce_comp_mega_mart_product_one' );
add_action( 'mega_mart_sections', 'ecommerce_comp_mega_mart_product_one', absint( $ecommerce_companion_section_priority ) );
}
?>