<?php
$logo_label = true;
$api_all_links = (!empty(get_field('sports_picks_link', 'option'))) ? get_field('sports_picks_link', 'option') : null;

if ($api_attributes['category_primary'] == '2') {
    $logo_label = false;
}

if ($api_attributes['category_primary'] == '7') {
    $logo_label = false;
}
?>

<?php foreach($picks as $pick):?>
    <div class="pick">
        <div class="pick-header">
            <div class="title">
                <span class="header-title">
                    <?php echo (isset($sports[$pick['id_sport']])) ? $sports[$pick['id_sport']] : ''; ?>
                </span>
            </div>
            <div class="content">
                <div class="sport"><span><?php echo $pick['sport_external']; ?></span></div>
                <div class="date-time"><span><?php echo $pick['game_date']; ?></span></div>
                <div class="status"><span><?php echo $pick['game_stat']; ?></span></div>
            </div>
        </div>
        <div class="pick-body">
            <div class="teams">
                <div class="team team-a">
                    <div class="team-logo">
                        <?php
                            $home_image = $block_sports_picks->get_image($pick['home_image'], [
                                'image_type' => 'team_image',
                                'image_alt' => $pick['home_name'],
                                'logo_label' => $logo_label
                            ]);
                        ?>
                        <img src="<?php echo $home_image['url']; ?>" alt="<?php echo $home_image['alt']; ?>">
                    </div>
                    <div class="team-name"><span><?php echo $pick['home_name']; ?></span></div>
                </div>
                <div class="team team-vs">
                    <div class="vs-logo"><span>vs</span></div>
                    <div class="vs-name"><span><?php echo $pick['num_picks']; ?> PICKS</span></div>
                </div>
                <div class="team team-b">
                    <div class="team-logo">
                        <?php
                            $visitor_image = $block_sports_picks->get_image($pick['visitor_image'], [
                                'image_type' => 'team_image',
                                'image_alt' => $pick['visitor_name'],
                                'logo_label' => $logo_label
                            ]);
                        ?>
                        <img src="<?php echo $visitor_image['url']; ?>" alt="<?php echo $visitor_image['alt']; ?>">
                    </div>
                    <div class="team-name"><span><?php echo $pick['visitor_name']; ?></span></div>
                </div>
            </div>
        </div>

        <?php if (!empty($api_all_links)): ?>
            <div class="pick-footer">
                <a href="<?php echo $api_all_links['url']; ?>" target="<?php echo (empty($api_all_links['target'])) ? '_self' : $api_all_links['target']; ?>"><?php echo $api_all_links['title']; ?></a>
            </div>
        <?php endif; ?>
    </div>
<?php endforeach; ?>
