<?php require dirname(__DIR__) . '/layouts/app.php'; ?>

<section class="page-heading">
    <div>
        <p class="eyebrow">Operations</p>
        <h1>Arrivees et departs</h1>
    </div>
    <div class="heading-actions">
        <a class="button-link secondary" href="<?= url('/operations/arrivals-departures?date=' . $previousDate) ?>">Precedent</a>
        <a class="button-link secondary" href="<?= url('/operations/arrivals-departures?date=' . $nextDate) ?>">Suivant</a>
    </div>
</section>

<form class="filter-panel client-filter" method="get" action="<?= url('/operations/arrivals-departures') ?>">
    <label>
        Date
        <input type="date" name="date" value="<?= e($date) ?>">
    </label>
    <button type="submit">Afficher</button>
</form>

<section class="stats-layout">
    <article class="table-panel">
        <h2 class="panel-title">Arrivees</h2>
        <table>
            <thead>
                <tr>
                    <th>Heure</th>
                    <th>Client</th>
                    <th>Telephone</th>
                    <th>Bien</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($arrivals as $reservation): ?>
                    <tr>
                        <td><?= e($reservation['checkin_time'] ?: '-') ?></td>
                        <td><?= e($reservation['first_name'] . ' ' . $reservation['last_name']) ?></td>
                        <td><?= e($reservation['phone'] ?: '-') ?></td>
                        <td><a href="<?= url('/reservations/show?id=' . $reservation['id']) ?>"><?= e($reservation['property_title']) ?></a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($arrivals)): ?>
                    <tr><td colspan="4">Aucune arrivee.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </article>

    <article class="table-panel">
        <h2 class="panel-title">Departs</h2>
        <table>
            <thead>
                <tr>
                    <th>Heure</th>
                    <th>Client</th>
                    <th>Telephone</th>
                    <th>Bien</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($departures as $reservation): ?>
                    <tr>
                        <td><?= e($reservation['checkout_time'] ?: '-') ?></td>
                        <td><?= e($reservation['first_name'] . ' ' . $reservation['last_name']) ?></td>
                        <td><?= e($reservation['phone'] ?: '-') ?></td>
                        <td><a href="<?= url('/reservations/show?id=' . $reservation['id']) ?>"><?= e($reservation['property_title']) ?></a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($departures)): ?>
                    <tr><td colspan="4">Aucun depart.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </article>
</section>

<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
