
<div class="row mr-0">
	<!-- <div class="headerbox "> -->
		<?php
		/**
		 * Template Name: Custom Home
		 */
		get_header(); ?>
	<!-- </div> -->
	<!-- <div class="col-lg-9 col-md-8 col-sm-12 "> -->

<main id="skip-content" role="main">
	<section id="banner-section">
		<div class="bg-img">
			<?php 
				$luzuk_sweet_delights_bakery_banner_bgimg = get_theme_mod('luzuk_sweet_delights_bakery_banner_bgimg');

				if(!empty($luzuk_sweet_delights_bakery_banner_bgimg)){
					echo '<img alt="'. esc_html(get_the_title()) .'" src="'.esc_url($luzuk_sweet_delights_bakery_banner_bgimg).'" class="img-responsive secondry-bg-img" />';
				}else{
					echo '<img alt="luzuk_sweet_delights_bakery_banner_bgimg" src="'.get_template_directory_uri().'/assets/images/banner.png" class="img-responsive" />';
				}
			?>
			<div class="overlay"></div>
		</div>
		<div class="conbx">
			<div class="row">
				<div class="rating">
					<i class="fa-solid fa-star"></i>
					<i class="fa-solid fa-star"></i>
					<i class="fa-solid fa-star"></i>
					<i class="fa-solid fa-star"></i>
					<i class="fa-solid fa-star"></i>
				</div>
				<div class="cltxt">
					<div class="txoly"></div>
					<span><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_ratingheading', 'Rated #1 Local Bakery')); ?></span>
				</div>
			</div>
			<h2><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_heading1', 'Fresh Baked')); ?></h2>
			<h3><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_heading2', 'Every Day')); ?></h3>
			<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_description', 'Artisan breads, pastries, and cakes made with love using traditional recipes and the finest ingredients.')); ?></p>
			<div class="banner-btn">
				<a class="lbtn" href="<?php echo esc_url(get_theme_mod('luzuk_sweet_delights_bakery_banner_button1_link', '#')); ?>">
					<?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_button1_text', 'Order Now')); ?>
					<i class="fa-solid fa-arrow-right"></i>
				</a>
				<a class="Rbtn" href="<?php echo esc_url(get_theme_mod('luzuk_sweet_delights_bakery_banner_button2_link', '#')); ?>">
					<?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_button2_text', 'View Menu')); ?>
					
				</a>
			</div>
			<div class="trustnumber">
				<div class="row">
					<div class="counterbx">
						<h2><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_yearofex_num', '25+')); ?></h2>
						<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_yearofex_text', 'Years Experience')); ?></p>
					</div>
					<div class="counterbx">
						<h2><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_happycust_num', '500+')); ?></h2>
						<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_happycust_text', 'Happy Customers Daily')); ?></p>
					</div>
					<div class="counterbx">
						<h2><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_freshdetail_num', '100%')); ?></h2>
						<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_banner_trustnumber_freshdetail_text', 'Fresh Ingredients')); ?></p>
					</div>
				</div>
			</div>
		</div>
	</section>

	<?php do_action('luzuk_sweet_delights_bakery_below_profile'); ?>

	<section id="featureproduct-section">
		<div class="container"> 
			<div class="featureproduct-head  ">
				<div class="section-title">
					<h5><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_featuredproducts_subheading')); ?></h5>

					<?php if(get_theme_mod('luzuk_sweet_delights_bakery_featuredproducts_heading') != ''){?>
						<h3><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_featuredproducts_heading')); ?></h3>
					<?php }?>
					<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_featuredproducts_head_descripton')); ?></p>
				</div>
			</div>
			<div class="row">  
					<?php
					if(function_exists('woocommerce_template_loop_add_to_cart') && function_exists('WC')){
						$meta_query   = WC()->query->get_meta_query();
						$tax_query   = WC()->query->get_tax_query();
						$tax_query[] = array(
							'taxonomy' => 'product_visibility',
							'field'    => 'name',
							'terms'    => 'featured',
							'operator' => 'IN',
						);
						$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; ?>
					<div class="item col-lg-4 col-md-6 col-sm-12 pd-1">  
						<div class="product-grid ">
							<!-- <div class="probg"></div> -->
							<div class="product-image">
								<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 class="pic-1" src="'.get_template_directory_uri().'/assets/images/default.png" alt="Placeholder" />'; ?>
									
								</a>
								<div class="tpf">
                                        <!-- discount -->
                                        <?php if ( $product->is_on_sale() ) : 
                                            $regular_price = (float) $product->get_regular_price();
                                            $sale_price    = (float) $product->get_sale_price();
                                            if ( $regular_price > 0 && $sale_price > 0 ) {
                                                $discount_percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
                                                echo '<p class="product-discount">' . esc_html( $discount_percentage ) . '% off</p>';
                                            }
                                        endif; ?>

                                        <!-- tags -->
                                        <?php
                                        $tags = get_the_terms( get_the_ID(), 'product_tag' );
                                        if ( $tags && ! is_wp_error( $tags ) ) {
                                            echo '<div class="product-tags">';
                                            foreach ( $tags as $tag ) {
                                                echo '<span class="tag-item">' . esc_html( $tag->name ) . '</span> ';
                                            }
                                            echo '</div>';
                                        }
                                        ?>

                                        <!-- rating -->
                                        <div class="product-rating">
                                            <?php 
                                            if ( wc_review_ratings_enabled() ) {
                                                $average = $product->get_average_rating();
                                                $count   = $product->get_rating_count();

                                                if ( $count > 0 && $average > 0 ) {
                                                    echo wc_get_rating_html( $average, $count ); 
                                                    echo '<span class="rating-number">⭐ ' . number_format( $average, 1 ) . '</span>';
                                                }
                                            }
                                            ?>
                                        </div>
                                    </div>
							</div>
							<div class="productcontent-wrap">
								<?php
									$productbutton = get_theme_mod('product_txt', 'Add to cart'); 
								?>

								<div class="pcontent">
									
									<a class="add-to-cart" id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">	
										<h4><?php the_title(); ?></h4>
									</a>
									 <div class="price">
		                                <?php 
		                                $regular_price = $product->get_regular_price(); 
		                                $sale_price    = $product->get_sale_price(); 

		                                if ( $product->is_on_sale() && $sale_price ) {
		                                    echo '<span class="sale-price">' . wc_price( $sale_price ) . '</span>';
		                                    echo '<span class="regular-price">' . wc_price( $regular_price ) . '</span>';
		                                } else {
		                                    echo '<span class="regular-price">' . wc_price( $regular_price ) . '</span>';
		                                }
		                                ?>
		                            </div>
									<!-- <span class="price"></?php echo $product->get_price_html(); ?></span> -->
									<?php if( get_theme_mod('product_button_display','show' ) == 'show') :
										?>	
										<div class="add-to-cart">
											<a href="<?php echo esc_url(get_permalink()); ?>" class="more-button"><span></span><?php echo ($productbutton );  ?></a>
										</div>
									<?php endif ?>
								</div>
								<div class="clearfix"></div>
							</div>
						</div>
					</div> 
					<?php
						endwhile; 
							}else{ ?>
						<div class="alert alert-warning text-center">
							<strong><?php _e( 'You havent Star Marked Feature Products.', 'sweet-delights-bakery' ); ?></strong>
						</div>
						<?php
								}
								?>
						<?php
							wp_reset_query(); 
						}else{ ?>
						<div class="alert alert-warning text-center">
							<?php _e( 'Please Install or Activate the WooCommerce plugin.', 'sweet-delights-bakery' ); ?>
						</div>
					<?php
					}?>
				</div> 
		</div>
	</section>

	<?php do_action('luzuk_sweet_delights_bakery_below_featureproduct'); ?>

	<section id="productcategory-section">
		<div class="container"> 
			<div class="sec-head">
				<div class="section-title">
					<h5><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_productcategory_subheading')); ?></h5>

					<?php if(get_theme_mod('luzuk_sweet_delights_bakery_productcategory_heading') != ''){?>
						<h3><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_productcategory_heading')); ?></h3>
					<?php }?>
					<p><?php echo esc_html(get_theme_mod('luzuk_sweet_delights_bakery_productcategory_head_descripton')); ?></p>
				</div>
			</div>
			<div class="p-sbox">
			
				<?php if(class_exists('woocommerce')){ ?>
					<div class="category">
						<div class="pcbox">
							<div class="row mr-0">  
							<?php
							$args = array(
								'number'     => 8,  // Limit to 8 categories
								'orderby'    => 'title',
								'order'      => 'ASC',
								'hide_empty' => false
							);
							$product_categories = get_terms('product_cat', $args);

							$count = count($product_categories);
							$limit = 8; // Set limit to 8
							if ($count > 0) {
								$counter = 0;
								foreach ($product_categories as $product_category) {
									if ($counter >= $limit) break; // Stop loop after 8 categories
									$counter++;

									$image = esc_html(get_template_directory_uri()).'/assets/images/default.png'; // Set default image

									if (function_exists('get_term_meta')) {
										if (isset($product_category->term_id)) {
											// Get the thumbnail ID
											$thumbnail_id = get_term_meta($product_category->term_id, 'thumbnail_id', true);
											if ($thumbnail_id) {
												// Get the image URL for parent category
												$image = wp_get_attachment_url($thumbnail_id);
											}
										}
									}

									if (isset($product_category->name)) {
									    echo '<div class="col-xl-3 col-lg-4 col-md-6 col-sm-12 item cat-product hvr-float-shadow">';
									     echo '<div class="catMinnbx">';
									    echo '<div class="pro-cat-img">
									            <a href="' . get_term_link($product_category) . '" data-hover="' . esc_attr($product_category->name) . '">
									                <img src="' . esc_url($image) . '" alt="' . esc_attr($product_category->name) . '" width="270" height="377" />
									                <div class="p-olay"></div>
									            </a>
									          </div>';

									    echo '<div class="pro-combx">  
									            <div class="pro-cat-content">
									                <h5>
									                    <a href="' . get_term_link($product_category) . '" data-hover="' . esc_attr($product_category->name) . '">
									                        ' . esc_html($product_category->name) . '
									                    </a>
									                </h5>
									                <p class="cat-description">' . esc_html($product_category->description) . '</p>
									                <div class="num">' . esc_html($product_category->count) . '</div>
									            </div>
									          </div>';

									    echo '</div>'; 
									    echo '</div>';
									}

								}
							}
							?>
							</div>
						</div>
						<div class="clearfix"></div>
					</div>

				<?php }?>
			</div>
		</div>
	</section>

	<?php do_action('luzuk_sweet_delights_bakery_below_productcategory'); ?>
	
	<div class="container">
	  	<?php while ( have_posts() ) : the_post(); ?>
	  		<div class="lz-content">
	        	<?php the_content(); ?>
	        </div>
	    <?php endwhile; // end of the loop. ?>
	</div>
</main>


<?php get_footer(); ?>

<!-- </div> -->
</div>

