<?php
/**
 * Home Section 1 Template - Modern Medical Layout
 *
 * @package Lifeline Hospital
 */

$subsection_title = get_theme_mod('lifeline_hospital_section1_subtitle', 'Explore Our Insights: Expert Healthcare Services Tailored for You');
$lifeline_hospital_section_one = get_theme_mod('lifeline_hospital_section1_enable');

if ('Disable' == $lifeline_hospital_section_one) {
    return;
}
?>

<section id="hospital-blog-section" class="hospital-blog py-5">
    <div class="container">
        <div class="text-center mb-5">
            <?php if (get_theme_mod('lifeline_hospital_section1_title', true) != '') : ?>
                <h2 class="hospital-section-title"><?php echo esc_html(get_theme_mod('lifeline_hospital_section1_title')); ?></h2>
            <?php endif; ?>
            <p class="hospital-section-subtitle"><?php echo esc_html($subsection_title); ?></p>
        </div>

        <div class="row g-4">
            <?php
            $args = array(
                'category_name' => get_theme_mod('lifeline_hospital_section1_category'),
                'posts_per_page' => get_theme_mod('lifeline_hospital_section1_category_number_of_posts_setting'),
                'order' => 'DESC'
            );
            $query = new WP_Query($args);

            while ($query->have_posts()) : $query->the_post(); ?>
                <div class="col-lg-4 col-md-6">
                    <div class="hospital-card shadow-lg h-100">
                        <?php if (has_post_thumbnail()) : ?>
                            <div class="hospital-card-img">
                                <a href="<?php the_permalink(); ?>">
                                    <?php the_post_thumbnail('large', ['class' => 'img-fluid w-100']); ?>
                                </a>
                            </div>
                        <?php endif; ?>

                        <div class="hospital-card-body p-4">
                            <?php if (get_theme_mod('lifeline_hospital_post_meta_toggle_switch_control', true)) : ?>
                                <div class="hospital-meta mb-2">
                                    <span><?php echo esc_html(get_the_date()); ?></span>
                                    <span class="mx-2">|</span>
                                    <span><?php echo esc_html(get_the_author()); ?></span>
                                </div>
                            <?php endif; ?>

                            <h3 class="hospital-card-title">
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h3>

                            <p class="hospital-card-excerpt"><?php echo wp_trim_words(get_the_excerpt(), 15); ?></p>

                            <a href="<?php the_permalink(); ?>" class="hospital-readmore-btn">Read More</a>
                        </div>
                    </div>
                </div>
            <?php endwhile;
            wp_reset_postdata(); ?>
        </div>
    </div>
</section>
