<?php
/**
 * @package luzuk Premium
 */

if (get_theme_mod('featured_products_area_disable') !== 'on') : ?>

<div class="featuredproducts-area" id="featuredproducts">
		<?php
		// width 
		$c_width = get_theme_mod('feaproduct_c_width', 'container');

	    if ($c_width === 'container') {
			    $c_alignment = 'container';
			} elseif ($c_width === 'container-fluid') {
			    $c_alignment = 'container-fluid';
			} else {
			    $text_alignment = 'container'; // Default to 'container' if the setting is invalid
			}

		// Sub Heading Style
    	$sub_heading_case = get_theme_mod('feaproduct_subtitle_case', 'uppercase');

		if ($sub_heading_case === 'uppercase') {
				$text_case = 'uppercase';
			} elseif ($sub_heading_case === 'lowercase') {
			    $text_case = 'lowercase';
			} elseif ($sub_heading_case === 'capitalize') {
			    $text_case = 'capitalize';
			} else {
			    $text_case = 'capitalize'; // Default to 'left' if the setting is invalid
			}

		// Heading Style
    	$heading_case = get_theme_mod('feaproduct_maintitle_case', 'uppercase');

		if ($heading_case === 'uppercase') {
				$text_case = 'uppercase';
			} elseif ($heading_case === 'lowercase') {
			    $text_case = 'lowercase';
			} elseif ($heading_case === 'capitalize') {
			    $text_case = 'capitalize';
			} else {
			    $text_case = 'capitalize'; // Default to 'left' if the setting is invalid
			}
				 
    ?>
	  <div class="<?php echo esc_attr($c_width); ?>">
	    <?php
	    $featuredproductsubtitle = get_theme_mod('featuredproductsubtitle', 'OUR PRICING');
	      $featureproduct_title = get_theme_mod('featureproduct_title', 'Service package pricing');
	      
	    ?>
		    <div class="section-title">	
						<div class="titlebx">
								<div class="sub_title" style="text-transform: <?php echo esc_attr($sub_heading_case); ?>; "><?php echo ($featuredproductsubtitle); ?></div>
								<h3 style=" text-transform: <?php echo esc_attr($heading_case); ?>;"><?php echo ($featureproduct_title); ?></h3>
						</div>
				</div>
		    <div class="featuredproductsus-post-wrap">
			      <div class="row mr-0">
			        <?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',
			            'posts_per_page' => -1,
			            'orderby'        => 'date',
			            'order'          => 'DESC',
			            'meta_query'     => $meta_query,
			            'tax_query'      => $tax_query,
			          );

			          $loop = new WP_Query($args);

			          if ($loop->have_posts()) :
			            while ($loop->have_posts()) : $loop->the_post();
			              global $product;
			              $product_id = $product->get_id();
			              $sale_text = get_post_meta(get_the_ID(), '_custom_product_salenew_field', true);
			              $discount_text = get_post_meta(get_the_ID(), '_custom_product_discount_field', true);
			              $button_text = get_theme_mod('button_text', 'Get A Plan');
			        ?>
				        <div class="featuredproductsbx" data-wow-duration="1s">
					          <div class="featuredproductsus-single">			            
					              <div id="quick-view-<?php the_ID(); ?>" class="quick-view-popup">
						                <div class="quick-view-content">
							                  <div class="product-details">
								                    <div class="row mr-0">   
								                      	<div class="productbx">
										                        <div class="title"> <?php the_title(); ?> </div>
										                        <div class="product-price">
										                           <?php echo $product->get_price_html(); ?>
										                        </div>
										                    </div>
										                    <div class="product-imagebx">
										                        <div class="product-image">
										                          <?php
											                          if (has_post_thumbnail()) {
											                            the_post_thumbnail('shop_single');
											                          } else {
											                            echo '<img src="' . get_template_directory_uri() . '/images/default.png" alt="featured product" />';
											                          }
										                          ?>
										                          <div class="imgbrd"></div>
										                        </div>    
										                    </div>
									                  </div>
									                  <div class="product-description">
									                      <?php the_content(); ?>   
									                      <?php if( $button_text  ){ ?>
									                      <div class="buy-now-button">
														                <a href="<?php echo esc_url(add_query_arg([
														                  'add-to-cart' => $product_id,
														                  'redirect_to' => 'checkout'
														                ], wc_get_cart_url())); ?>" class="button buy-now">
														                <?php echo esc_html($button_text); ?>
														                </a>
													              </div>
													              <?php }?> 
								                    </div>
							                  </div>
						                </div>
					              </div>
					                
					          </div>
				        </div>
			        <?php
			            endwhile;
			          endif;
			          wp_reset_postdata();
			        }
			        ?>
			      </div>
		    </div>
	  </div>
</div>

<?php endif; ?>