<?php
/**
 * Theme Section One
 *
 * @package Pawprints Blog
 */

// All Function code and function definitions go here...

$pawprints_blog_section_one = get_theme_mod('pawprints_blog_section1_enable');
if ('Disable' === $pawprints_blog_section_one) {
    return;
}
?>

<section id="section1" class="featured-posts">
    <div class="container">
        <div class="section-heading-main">
            <?php if (get_theme_mod('pawprints_blog_section1_enable_section_title', true) != '') { ?>
                <h3><?php echo esc_html(get_theme_mod('pawprints_blog_section1_enable_section_title')); ?></h3>
                <p><?php echo esc_html(get_theme_mod('pawprints_blog_section1_enable_section_text')); ?></p>
            <?php } ?>
        </div>
        <div class="row">
            <div class="col-lg-12 col-12">
                <div class="row">
                    <?php
                    // Define the query to get the latest posts from the specified category
                    $args = array(
                        'category_name' => get_theme_mod('pawprints_blog_section1_category'),
                        'posts_per_page' => get_theme_mod('pawprints_blog_section1_category_number_of_posts_setting', 5), // default to 5 if not set
                        'order' => 'DESC',
                    );

                    $query = new WP_Query($args);

                    // Loop through the posts
                    while ($query->have_posts()) : $query->the_post();
                    ?>
                        <div class="col-lg-12 col-md-12 col-sm-12 post-main-box">
                            <div class="row">
                                <div class="col-lg-6 col-12">
                                    <?php if (has_post_thumbnail()) : ?>
                                        <div class="post-thumbnail">
                                            <a href="<?php the_permalink(); ?>">
                                                <?php the_post_thumbnail(); ?>
                                            </a>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <div class="col-lg-6 col-12">
                                    <div class="post-section-box">
                                        <div class="post">
                                            <div class="main-content-postbox">
                                                <?php if (get_theme_mod('pawprints_blog_post_meta_toggle_switch_control', true)) : ?>
                                                    <div class="sec2-meta">
                                                        <span><?php echo esc_html(get_the_date()); ?></span>
                                                        <span class="separator">|</span>
                                                        <span><?php echo esc_html(get_the_author()); ?></span>
                                                    </div>
                                                <?php endif; ?>
                                                <h2 class="post-title">
                                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                                </h2>
                                                <div class="latest-content">
                                                    <?php the_content(); ?>
                                                </div>
                                                <?php if (get_theme_mod('pawprints_blog_post_readmore_toggle_switch_control', true)) : ?>
                                                    <div class="readmore-latest">
                                                        <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More', 'pawprints-blog'); ?></a>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endwhile; wp_reset_postdata(); ?>
                </div>
            </div>
        </div>
    </div>
</section>
