<?php

if (!isset($teamSchedulesBlockDataLoader)) {
    $teamSchedulesBlockDataLoader = new \Rdgcorp\Blocks\TeamSchedules\BlockDataLoader();
}

$teamId = get_field('team');
$seasonId = get_field('season');

$schedules = ($teamId && $seasonId) ? $teamSchedulesBlockDataLoader->getSchedules($teamId, $seasonId) : [];

?>

<div class="rdg-blocks">
    <div class="rdg-team-schedules">
        <?php if (count($schedules)): ?>
            <table>
                <?php foreach ($schedules as $schedule): ?>
                    <tr>
                        <td><?php echo $schedule['week']; ?></td>
                        <td><?php echo $schedule['date']; ?></td>
                        <td><?php echo $schedule['opponent']; ?></td>
                        <td><?php echo $schedule['result']; ?></td>
                    </tr>
                <?php endforeach; ?>
            </table>

        <?php elseif ($teamId): ?>
            <p>No schedules found.</p>
        <?php else: ?>
            <p>Please complete the form.</p>
        <?php endif; ?>
    </div>
</div>
