<?php
get_header();
?>

<main class="project-archive">
    <div class="site-container">

        <section class="project-archive__header">
            <h1>
                <?php post_type_archive_title(); ?>
            </h1>
        </section>

        <?php
        $query = new WP_Query(array(
            'post_type' => 'project',
            'posts_per_page' => -1,
            'orderby' => 'date',
            'order' => 'ASC'
        ));
        ?>

        <?php if ($query->have_posts()): ?>

            <section class="project-archive__grid">

                <?php while ($query->have_posts()):
                    $query->the_post(); ?>

                    <article class="project-card">
                        <a class="project-card__link" href="<?php the_permalink(); ?>">

                            <div class="project-card__media">
                                <?php the_post_thumbnail(
                                    'full',
                                    array(
                                        'class' => 'project-card__image',
                                        'loading' => 'lazy',
                                        'decoding' => 'async',
                                    )
                                ); ?>
                            </div>

                            <div class="project-card__body">
                                <h2 class="project-card__title">
                                    <?php the_title(); ?>
                                </h2>
                            </div>

                        </a>
                    </article>

                <?php endwhile; ?>

            </section>

            <?php wp_reset_postdata(); ?>

        <?php endif; ?>

        <section class="project-archive__cta">
            <?php get_template_part('template-parts/content', 'cta'); ?>
        </section>

    </div>
</main>

<?php get_footer(); ?>