<?php
/**
 *
 * @package luzuk Premium
 */
if(get_theme_mod('blog_section_disable') != 'on' ){ ?>

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

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

		// Alientment
        $heading_alignment = get_theme_mod('blog_maintitle_align', 'left');

	    if ($heading_alignment === 'left') {
			$text_alignment = 'left';
		} elseif ($heading_alignment === 'center') {
		    $text_alignment = 'center';
		} elseif ($heading_alignment === 'right') {
		    $text_alignment = 'right';
		} else {
		    $text_alignment = 'left'; // Default to 'left' if the setting is invalid
		}

		//sub Heading Style
		$subheading_case = get_theme_mod('blog_subtitle_case', 'uppercase');

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

		// Heading Style
    	$heading_case = get_theme_mod('blog_maintitle_case', 'capitalize');

	    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
		}
			 
		
    ?>
	<?php
		$blog_txt = get_theme_mod('blog_txt', 'Blog Post ');  
        $blog_title = get_theme_mod('blog_title', 'News & Updates');
        
    ?>
    <div class="<?php echo esc_attr($c_width); ?> cf-ps">
    	<div class="section-title">        
            <div class="titlebx" style="text-align: <?php echo esc_attr($text_alignment); ?>;">
	            <h2 style="text-transform: <?php echo esc_attr($subheading_case); ?>;"><?php echo ($blog_txt); ?></h2>
	            <h3 style="text-transform: <?php echo esc_attr($heading_case); ?>;"><?php echo ($blog_title); ?></h3>
            </div>     
		</div>                 
		<div class="blog-area-wrap">
			<div class="blog-posts">
				<div class="row mr-0">
					<?php 
						$blog_post_count = get_theme_mod('blog_post_count', 4 );
						$blog_cat_exclude = get_theme_mod('blog_cat_exclude');
						$blog_cat_exclude = explode(',', $blog_cat_exclude);
						$args = array(
							'posts_per_page' => absint($blog_post_count),
							'category__not_in' => $blog_cat_exclude
						);
						$query = new WP_Query($args);
						if($query -> have_posts()):
							while($query -> have_posts()) : $query -> the_post();
							$luzuk_blog_image = wp_get_attachment_image_src(get_post_thumbnail_id() , 'total-blog-thumb');
							?>
							<?php 
							if(has_post_thumbnail()){
								$img = esc_url($luzuk_blog_image[0]);
							}
							if(empty($luzuk_blog_image)){
								$img = get_template_directory_uri().'/images/blog.jpg';
							}
					?>
					<div class="blog-post col-xl-3 col-lg-3 col-md-6 col-sm-6">
						<div class="box-area-S ">
							<div class="blog-image">
								<a href="<?php the_permalink(); ?>">
									<img class="blog-img" src="<?php echo $img; ?>" alt="<?php the_title(); ?>">
									<div class="link"></div>
									<div class="link2"></div>
								</a>
							</div>							
							<div class="blog-single">
							    <div class="blog-admin">
									<li> <?php echo get_the_date( 'M, j Y' ); ?> </li> <li> <i class="fa fa-circle"></i><?php echo get_the_author(); ?> </li>
								</div>
							    <a href="<?php the_permalink(); ?>">
							        <h4 class="inner-area-title"><?php the_title(); ?></h4>
							    </a>	    
							    <p>
							        <?php 
							            if ( has_excerpt() ) {
							                echo get_the_excerpt();
							            } else {
							                echo luzuk_excerpt( get_the_content(), 90 ); 
							            }
							        ?>
							    </p>
							    <?php
							    	$blogbtn_text = get_theme_mod('blogbtn_text', 'Read More');
							    ?>
							    <?php if($blogbtn_text ){ ?>	
							    <div class="blog-btn">
									<a href="<?php echo esc_url(get_permalink()); ?>">
										<?php echo ($blogbtn_text); ?>
									</a>
								</div>
								<?php }?>
							</div>

						</div>
						<div class="clearfix"></div>
					</div>
					<?php
						endwhile;
						endif;
						wp_reset_postdata();
					?>
				</div>
			</div>
			<div class="clearfix"></div>
		</div>	
		<?php
			$blgbttn_text = get_theme_mod('blgbttn_text', 'View more articles');
			$blgbttnlink = get_theme_mod('blgbttnlink', '#');
		?>
		<?php if( $blgbttn_text  ){ ?>	
		<div class="blg-btn">				
			<a href="<?php echo ($blgbttnlink);  ?>" >
    			<?php echo($blgbttn_text); ?> <i class="fa-solid fa-arrow-right"></i>
			</a>	
		</div>	
		<?php }?>
	</div>
	<div class="clearfix"></div>
</div>

<?php }