<?php
/*
Template Name: Portfolio
*/
get_header();

$currentPageId = get_the_ID();
?>

<section class="portfolio-archive projects-overview">

    <?php
    $args = array(
        'post_type' => 'portfolio',
        'posts_per_page' => -1,
    );
    $portfolio_post = new WP_Query($args);
    ?>
    <?php if ($portfolio_post->have_posts()) : while ($portfolio_post->have_posts()) : $portfolio_post->the_post(); ?>
            <?php
            $projectThumbnailUrl = get_the_post_thumbnail_url($portfolio_post->ID, 'full');
            $projectPermLink = get_the_permalink($portfolio_post->ID);
            $excerpt = get_the_excerpt();
            $clientName = get_field('client_name', $portfolio_post->ID);
            $terms = get_the_terms($portfolio_post->ID, 'project_type');

            ?>
            <div class="portfolio-project-card portfolio-project-card--active">
                <a class="portfolio-project-card__cover" href="<?php echo $projectPermLink ?>">
                    <img src="<?php echo $projectThumbnailUrl ?>" alt="">

                </a>
                <div class="portfolio-project-card__details">
                    <div>
                        <h2 class="client-name"><?php echo $clientName ?></h2>
                        <div class="terms">
                            <?php foreach ($terms as $term): ?>
                                <span>#<?php echo $term->name ?></span>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <div class='excerpt'>
                        <h3><?php the_title(); ?></h3>
                        <p><?php echo $excerpt ?></p>
                        <a class="cta--read-project" href="<?php the_permalink(); ?>">
                            <span>Voir le projet</span>
                        <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/graphic-assets/arrow-see-project.svg" alt="Voir le projet">
                        </a>
                    </div>
                </div>

            </div>
        <?php endwhile; ?>
    <?php endif; ?>
</section>

<section class="old-projects ">
    <?php
    $portfolio_beta = get_field('portfolio_beta', $currentPageId);
    ?>

    <?php foreach ($portfolio_beta as $portfolio_project): ?>
        <?php
        $image = get_sub_field('image_du_projet');
        $imageMobile = get_sub_field('image_du_projet_mobile');
        $projectName =   $portfolio_project['nom_du_projet'];
        $clientName =   $portfolio_project['nom_du_client'];
        $projectDescription =   $portfolio_project['description_du_projet'];
        $projectThumbnail = $portfolio_project['image_du_projet'];
        $imageMobile = $portfolio_project['image_du_projet_mobile'];
        $categorie = $portfolio_project['categorie_du_projet'];
        ?>

        <div class="portfolio-project-card portfolio-project-card--inactive">
            <div class="portfolio-project-card__cover" href="<?php echo $projectPermLink ?>">
                <!-- <img src="<?php echo $projectThumbnailUrl ?>" alt=""> -->
                <img class="large <?php echo $mouse; ?>" src="<?php echo $projectThumbnail['url']; ?>" alt="<?php echo $projectThumbnail['alt'] ?>">
                <img class="mobile" src="<?php echo $imageMobile['url']; ?>" alt="<?php echo $imageMobile['alt'] ?>">
            </div>
            <div class="portfolio-project-card__details">
                <div>
                    <h2 class="client-name"><?php echo $clientName ?></h2>
                    <div class="terms">
                        <?php if (isset($categorie['value'])): ?>
                            <span>#<?php echo $categorie['value'] ?></span>
                        <?php endif; ?>
                    </div>
                </div>

                <div class='excerpt'>
                    <h3><?php echo $projectName ?></h3>
                    <p><?php echo $projectDescription ?></p>
                </div>
            </div>

        </div>

    <?php endforeach; ?>

    </div>
</section>

<?php get_footer(); ?>