<?php get_header(); ?>

<main id="primary" class="site-main">
    <div class="container">
        <div class="content-area">

            <?php if ( have_posts() ) : ?>

                <div class="archive-posts-grid">
                    <?php while ( have_posts() ) : the_post(); ?>
                        <article id="post-<?php the_ID(); ?>" <?php post_class('post archive-post-card'); ?>>

                            <?php if ( has_post_thumbnail() ) : ?>
                                <div class="archive-card-thumb">
                                    <a href="<?php the_permalink(); ?>">
                                        <?php the_post_thumbnail('medium_large', array('loading' => 'lazy')); ?>
                                    </a>
                                </div>
                            <?php endif; ?>

                            <div class="archive-card-body">

                                <?php $cats = get_the_category(); if ( $cats ) : ?>
                                    <div class="archive-card-cats">
                                        <a href="<?php echo esc_url( get_category_link( $cats[0]->term_id ) ); ?>" class="post-category-badge">
                                            <?php echo esc_html( $cats[0]->name ); ?>
                                        </a>
                                    </div>
                                <?php endif; ?>

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

                                <div class="archive-card-meta">
                                    <span><i class="fas fa-calendar-alt"></i> <?php echo esc_html( get_the_date() ); ?></span>
                                    <span><i class="fas fa-user"></i> <?php the_author(); ?></span>
                                </div>

                                <div class="archive-card-excerpt">
                                    <?php the_excerpt(); ?>
                                </div>

                                <a href="<?php the_permalink(); ?>" class="archive-card-read-more">
                                    <?php _e('Weiterlesen', 'minecraft-modern-theme'); ?> <i class="fas fa-arrow-right"></i>
                                </a>

                            </div>
                        </article>
                    <?php endwhile; ?>
                </div>

                <!-- FIX: Pagination fehlte komplett -->
                <div class="archive-pagination">
                    <?php
                    the_posts_pagination( array(
                        'mid_size'  => 2,
                        'prev_text' => '<i class="fas fa-chevron-left"></i> ' . __('Zurück', 'minecraft-modern-theme'),
                        'next_text' => __('Weiter', 'minecraft-modern-theme') . ' <i class="fas fa-chevron-right"></i>',
                    ) );
                    ?>
                </div>

            <?php else : ?>

                <div class="no-posts-found">
                    <i class="fas fa-inbox fa-2x"></i>
                    <p><?php _e('Keine Beiträge gefunden.', 'minecraft-modern-theme'); ?></p>
                </div>

            <?php endif; ?>

        </div>
    </div>
</main>

<?php get_footer(); ?>