<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="mb-3">
    <a href="<?= site_url('group-bookings/new') ?>" class="text-decoration-none small">&larr; Back</a>
    <h1 class="h4 mb-1 mt-1"><?= esc($groupName) ?></h1>
    <p class="text-muted mb-0"><?= esc(date('d M Y', strtotime($checkIn))) ?> &rarr; <?= esc(date('d M Y', strtotime($checkOut))) ?> &middot; <?= count($rooms) ?> room<?= count($rooms) === 1 ? '' : 's' ?> found</p>
</div>

<?php if ($shortfall > 0): ?>
<div class="alert alert-warning">
    <i class="bi bi-exclamation-triangle me-1"></i>
    Only <?= count($rooms) ?> room(s) were actually available for these dates &mdash; <?= $shortfall ?> fewer than requested. Adjust dates or proceed with what's available below.
</div>
<?php endif; ?>

<div class="card shadow-sm">
    <div class="card-body">
        <p class="text-muted small">Enter a name and phone for every room you want to actually book &mdash; leave a row blank to skip that room.</p>

        <form action="<?= site_url('group-bookings') ?>" method="post">
            <?= csrf_field() ?>
            <input type="hidden" name="group_name" value="<?= esc($groupName) ?>">
            <input type="hidden" name="corporate_account_id" value="<?= esc($corporateAccountId) ?>">
            <input type="hidden" name="organizer_name" value="<?= esc($organizerName) ?>">
            <input type="hidden" name="organizer_phone" value="<?= esc($organizerPhone) ?>">
            <input type="hidden" name="organizer_email" value="<?= esc($organizerEmail) ?>">
            <input type="hidden" name="notes" value="<?= esc($notes) ?>">
            <input type="hidden" name="check_in_date" value="<?= esc($checkIn) ?>">
            <input type="hidden" name="check_out_date" value="<?= esc($checkOut) ?>">

            <div class="table-scroll">
                <table class="table align-middle">
                    <thead>
                        <tr>
                            <th>Room</th>
                            <th>Type</th>
                            <th>Rate/Night</th>
                            <th>Guest Name</th>
                            <th>Phone</th>
                            <th>Email <span class="text-muted fw-normal">(optional)</span></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($rooms as $i => $room): ?>
                            <tr>
                                <td class="fw-semibold"><?= esc($room->room_number) ?>
                                    <input type="hidden" name="room_id[]" value="<?= $room->id ?>">
                                </td>
                                <td><?= esc($room->room_type_name) ?></td>
                                <td><?= format_money($room->resolved_rate) ?></td>
                                <td><input type="text" class="form-control form-control-sm" name="guest_name[]" placeholder="Full name"></td>
                                <td><input type="text" class="form-control form-control-sm" name="guest_phone[]" placeholder="024..."></td>
                                <td><input type="email" class="form-control form-control-sm" name="guest_email[]"></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>

            <button type="submit" class="btn btn-primary mt-2"><i class="bi bi-check2-circle me-1"></i>Confirm Group Booking</button>
        </form>
    </div>
</div>

<?= $this->endSection() ?>
