<?php get_header(); ?>

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

            <header class="search-header">
                <div class="archive-type-badge">
                    <i class="fas fa-search"></i> <?php _e('Suchergebnisse', 'minecraft-modern-theme'); ?>
                </div>
                <?php global $wp_query; ?>
                <p class="search-result-count">
                    <?php printf(
                        _n('%d Ergebnis gefunden', '%d Ergebnisse gefunden', $wp_query->found_posts, 'minecraft-modern-theme'),
                        $wp_query->found_posts
                    ); ?>
                </p>

                <!-- Suchformular zum Verfeinern -->
                <div class="search-refine">
                    <?php get_search_form(); ?>
                </div>
            </header>

            <?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">

                                <div class="archive-card-type">
                                    <?php
                                    $pt = get_post_type_object( get_post_type() );
                                    echo '<span class="post-type-badge"><i class="fas fa-file-alt"></i> ' . esc_html($pt->labels->singular_name) . '</span>';
                                    ?>
                                </div>

                                <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('Zum Beitrag', 'minecraft-modern-theme'); ?> <i class="fas fa-arrow-right"></i>
                                </a>

                            </div>
                        </article>

                    <?php endwhile; ?>
                </div>

                <!-- Pagination -->
                <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-search fa-3x" style="opacity:0.3; margin-bottom:20px;"></i>
                    <h2><?php _e('Keine Ergebnisse gefunden', 'minecraft-modern-theme'); ?></h2>
                    <p><?php printf( __('Deine Suche nach <strong>%s</strong> hat keine Treffer ergeben.', 'minecraft-modern-theme'), esc_html( get_search_query() ) ); ?></p>
                    <p><?php _e('Versuche es mit anderen Suchbegriffen oder schau dir unsere letzten Beiträge an.', 'minecraft-modern-theme'); ?></p>
                    <?php get_search_form(); ?>
                </div>

            <?php endif; ?>

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

<?php get_footer(); ?>