<?php
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Archive Template für CPT "mobile-api-vehicle"
 */

get_header(); ?>

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

    <header class="page-header">
        <h1 class="page-title"><?php post_type_archive_title(); ?></h1>
    </header>

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

        <div class="vehicle-archive-grid">
            <?php
            while ( have_posts() ) :
                the_post();
            ?>
                <article id="post-<?php the_ID(); ?>" <?php post_class( 'vehicle-archive-item' ); ?>>
                    
                    <a href="<?php the_permalink(); ?>">
                        <?php if ( has_post_thumbnail() ) : ?>
                            <div class="vehicle-thumbnail">
                                <?php the_post_thumbnail( 'medium' ); ?>
                            </div>
                        <?php endif; ?>
                        <h2 class="vehicle-title"><?php the_title(); ?></h2>
                    </a>

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

                    <?php
                    $mobile_api_vehicle_category = get_the_terms( get_the_ID(), 'mobile_api_vehicle_category' );
                    if ( $mobile_api_vehicle_category && ! is_wp_error( $mobile_api_vehicle_category ) ) :
                        echo '<div class="vehicle-categories"><strong>Categories:</strong> ';
                        echo esc_html( implode( ', ', wp_list_pluck( $mobile_api_vehicle_category, 'name' ) ) );
                        echo '</div>';
                    endif;
                    ?>
                </article>
            <?php endwhile; ?>
        </div>

        <div class="vehicle-pagination">
            <?php
            the_posts_pagination( array(
                'mid_size'  => 2,
                'prev_text' => esc_html__( '← Previous', 'ad-integration-for-mobile-de-api' ),
                'next_text' => esc_html__( 'Next →', 'ad-integration-for-mobile-de-api' )
            ) );
            ?>
        </div>

    <?php else : ?>

        <p><?php esc_html_e( 'No vehicles found.', 'ad-integration-for-mobile-de-api' ); ?></p>

    <?php endif; ?>

    <?php get_sidebar(); ?>

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

<?php get_footer(); ?>