<?php
require __DIR__ . '/../../director.php';
require __DIR__ . '/../../views.php';
require_once __DIR__ . '/../../../view/debug.php';

if (isset($_GET['loc'])) {
    $loc = $_GET['loc'];
}

if (isset($_GET['serviceId'])) {
    $serviceId = $_GET['serviceId'];
} else {
    $serviceId = null;
}

if (isset($_GET['scheduledArrival'])) {
    $scheduledArrival = $_GET['scheduledArrival'];
} else {
    $scheduledArrival = null;
}

if (isset($_GET['arrivalBoardedIndex'])) {
    $arrivalBoardedIndex = $_GET['arrivalBoardedIndex'];
} else {
    $arrivalBoardedIndex = null;
}

$searchOptions = $_GET['opt'] ?? null;

$response = Director::ConnectionsBoard($loc, $serviceId, $scheduledArrival, $arrivalBoardedIndex, $searchOptions); ?>

<span style="font-weight: bold;">Connections from <?= $response->locationName ?></span>
<table>
    <thead>
        <tr>
            <th class="ap-inline-connection-status">Status</th>
            <th class="ap-inline-time">Time</th>
            <th class="ap-inline-platform">From</th>
            <th class="ap-inline-destination">Destination</th>
            <th class="ap-inline-expected">Expected</th>
        </tr>
    </thead>

    <tbody>

        <?php
        if (count($response->departures->services) === 0) {
            echo '<tr><td colspan="5">No connections found. This can happen at the beginning or end of the day, or when there are no services to different locations within a reasonable time.</td></tr>';
        } else {
            foreach ($response->departures->services as $service) :
                show_connections_board_details($service, true);
            endforeach;
        }
        ?>

    </tbody>
</table>