<?php get_header(); ?>

<div class="container site-main">
    <div class="content-area">
        <div class="team-archive-container">
            <header class="page-header">
                <h1 class="page-title">Unser Team</h1>
                <p class="page-description">Lerne die Leute kennen, die diesen Server am Laufen halten.</p>
            </header>

            <?php
            $query = new WP_Query(array('post_type' => 'team_member', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC'));
            if ( $query->have_posts() ) : ?>
                <div class="team-grid">
                    <?php while ( $query->have_posts() ) : $query->the_post();
                        $rank_string = get_post_meta( get_the_ID(), '_team_member_rank', true );
                        $img = get_the_post_thumbnail_url( get_the_ID(), 'medium' );
                        if ( !$img ) $img = get_template_directory_uri() . '/images/default-avatar.png';
                    ?>
                    <article class="team-card">
                        <div class="team-image-wrapper">
                            <img src="<?php echo esc_url($img); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
                        </div>
                        <div class="team-info">
                            <h3 class="team-name"><?php the_title(); ?></h3>
                            <div class="team-ranks-wrapper">
                                <?php if ( !empty($rank_string) ) {
                                    $ranks = explode(',', $rank_string);
                                    foreach ( $ranks as $r ) {
                                        echo '<span class="team-rank">' . esc_html(trim($r)) . '</span>';
                                    }
                                } ?>
                            </div>
                            <div class="team-bio"><?php the_excerpt(); ?></div>
                        </div>
                    </article>
                    <?php endwhile; ?>
                </div>
                <?php wp_reset_postdata(); ?>
            <?php else : ?>
                <p>Noch keine Teammitglieder.</p>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php get_footer(); ?>