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

<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card shadow-sm mb-3">
            <div class="card-body text-center py-5">
                <div class="mb-3"><i class="bi bi-check-circle-fill text-success" style="font-size: 3rem;"></i></div>
                <h1 class="h3 mb-1">Reservation Confirmed!</h1>
                <p class="text-muted">Your reservation has been successfully created.</p>
            </div>
        </div>

        <div class="card shadow-sm mb-3">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-start mb-3">
                    <div>
                        <div class="text-muted small">Reservation #</div>
                        <div class="fs-5 fw-bold">BK-<?= sprintf('%04d', $booking->id) ?></div>
                    </div>
                    <span class="badge bg-<?= esc($lookups->bookingStatuses[$booking->status]['badge'] ?? 'secondary') ?> fs-6"><?= esc($lookups->bookingStatuses[$booking->status]['label'] ?? ucfirst($booking->status)) ?></span>
                </div>
                <div class="row row-cols-2 g-3 small">
                    <div class="col"><span class="text-muted">Guest</span><br><span class="fw-semibold"><?= esc($booking->guest_name) ?></span></div>
                    <div class="col"><span class="text-muted">Room</span><br><span class="fw-semibold"><?= esc($booking->room_number) ?> — <?= esc($booking->room_type_name) ?></span></div>
                    <div class="col"><span class="text-muted">Check-in</span><br><span class="fw-semibold"><?= esc(date('d M Y', strtotime($booking->check_in_date))) ?>, 2:00 PM</span></div>
                    <div class="col"><span class="text-muted">Check-out</span><br><span class="fw-semibold"><?= esc(date('d M Y', strtotime($booking->check_out_date))) ?>, 12:00 PM</span></div>
                    <div class="col"><span class="text-muted">Nights</span><br><span class="fw-semibold"><?= $nights ?></span></div>
                    <div class="col"><span class="text-muted">Guests</span><br><span class="fw-semibold"><?= (int) $booking->adults ?> Adult<?= (int) $booking->adults !== 1 ? 's' : '' ?><?= $booking->children > 0 ? ', ' . (int) $booking->children . ' Child' . ($booking->children !== 1 ? 'ren' : '') : '' ?></span></div>
                    <?php if (! empty($serviceItems)): ?>
                    <div class="col-12"><span class="text-muted">Services</span><br>
                        <span class="fw-semibold"><?= implode(', ', array_map(static fn ($i) => $i->service_name . ' (' . $i->quantity . ')', $serviceItems)) ?></span>
                    </div>
                    <?php endif; ?>
                </div>

                <hr>

                <div class="row row-cols-2 g-3 small">
                    <div class="col"><span class="text-muted">Total Amount</span><br><span class="fw-semibold fs-5"><?= format_money($grandTotal) ?></span></div>
                    <div class="col"><span class="text-muted">Paid</span><br><span class="fw-semibold text-success"><?= format_money($paid) ?></span></div>
                    <div class="col"><span class="text-muted">Balance</span><br><span class="fw-semibold <?= (float) $balance > 0 ? 'text-danger' : 'text-success' ?>"><?= format_money($balance) ?></span></div>
                    <div class="col"><span class="text-muted">Payment Method</span><br><span class="fw-semibold"><?= esc($lookups->paymentMethods[$booking->initial_payment_method]['label'] ?? '—') ?></span></div>
                </div>

                <?php if ($booking->status === 'pending_deposit'): ?>
                    <div class="alert alert-warning small mt-3 mb-0">This booking is held pending the guest paying the deposit link that was just sent.</div>
                <?php endif; ?>
            </div>
        </div>

        <div class="d-flex flex-wrap gap-2 justify-content-center mb-3 no-print">
            <button type="button" class="btn btn-outline-secondary btn-sm" onclick="window.print()"><i class="bi bi-printer me-1"></i>Print Reservation</button>
            <a href="<?= site_url('bookings/wizard/confirmation/' . $booking->id . '/pdf') ?>" class="btn btn-outline-secondary btn-sm" target="_blank"><i class="bi bi-file-earmark-pdf me-1"></i>Download PDF</a>
            <?php if ($booking->guest_email): ?>
            <form action="<?= site_url('bookings/wizard/confirmation/' . $booking->id . '/email') ?>" method="post" class="d-inline">
                <?= csrf_field() ?>
                <button type="submit" class="btn btn-outline-secondary btn-sm"><i class="bi bi-envelope me-1"></i>Send Email</button>
            </form>
            <?php endif; ?>
            <form action="<?= site_url('bookings/wizard/confirmation/' . $booking->id . '/sms') ?>" method="post" class="d-inline">
                <?= csrf_field() ?>
                <button type="submit" class="btn btn-outline-secondary btn-sm"><i class="bi bi-chat-dots me-1"></i>Send SMS</button>
            </form>
        </div>

        <div class="d-flex gap-2 justify-content-center no-print">
            <a href="<?= site_url('bookings/new') ?>" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>New Booking</a>
            <a href="<?= site_url('bookings/' . $booking->id) ?>" class="btn btn-outline-primary"><i class="bi bi-eye me-1"></i>View Reservation</a>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
<?= $this->section('styles') ?>
@media print { .sidebar, .topbar, .no-print { display: none !important; } }
<?= $this->endSection() ?>
