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

<div class="row g-3">
    <div class="col-lg-7">
        <div class="card mb-3">
            <div class="card-header d-flex align-items-center gap-2">
                <i class="bi bi-person" style="color: var(--brand);"></i> Guest &amp; Reservation
            </div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-6">
                        <div class="text-muted small text-uppercase fw-bold mb-1">Guest</div>
                        <div class="fw-semibold"><?= esc($booking->guest_name) ?></div>
                        <div class="text-muted small"><?= esc($booking->guest_phone) ?></div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-muted small text-uppercase fw-bold mb-1">Room</div>
                        <div class="fw-semibold"><?= esc($booking->room_number) ?></div>
                        <div class="text-muted small"><?= esc($booking->room_type_name) ?></div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-muted small text-uppercase fw-bold mb-1">Check-in</div>
                        <div class="fw-semibold"><?= esc(date('d M Y', strtotime($booking->check_in_date))) ?></div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-muted small text-uppercase fw-bold mb-1">Check-out</div>
                        <div class="fw-semibold"><?= esc(date('d M Y', strtotime($booking->check_out_date))) ?></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-header d-flex align-items-center gap-2">
                <i class="bi bi-card-checklist" style="color: var(--brand);"></i> Confirm Guest ID
            </div>
            <div class="card-body">
                <form action="<?= site_url('checkin/' . $booking->id) ?>" method="post">
                    <?= csrf_field() ?>
                    <div class="row g-3 mb-3">
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold" for="id_type">ID Type</label>
                            <select class="form-select" id="id_type" name="id_type">
                                <option value="">—</option>
                                <?php foreach ($lookups->guestIdTypes as $key => $meta): ?>
                                    <option value="<?= esc($key) ?>" <?= ($guest->id_type ?? '') === $key ? 'selected' : '' ?>><?= esc($meta['label']) ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold" for="id_number">ID Number</label>
                            <input type="text" class="form-control" id="id_number" name="id_number" value="<?= esc($guest->id_number ?? '') ?>">
                        </div>
                    </div>

                    <div class="info-box mb-3 d-flex gap-2">
                        <i class="bi bi-info-circle" style="color: var(--brand);"></i>
                        <div class="small text-muted">Checking in will mark room <strong class="text-dark"><?= esc($booking->room_number) ?></strong> as <strong class="text-dark">Occupied</strong> and open a folio with room charges for each night of the stay.</div>
                    </div>

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-success"><i class="bi bi-check2-circle me-1"></i>Complete Check-In</button>
                        <a href="<?= site_url('checkin') ?>" class="btn btn-outline-secondary">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-lg-5">
        <div class="card">
            <div class="card-header">Stay Summary</div>
            <div class="card-body">
                <div class="d-flex justify-content-between small mb-2">
                    <span class="text-muted">Nights</span>
                    <span class="fw-semibold"><?= $nights ?></span>
                </div>
                <div class="d-flex justify-content-between small mb-2">
                    <span class="text-muted">Room Rate</span>
                    <span class="fw-semibold"><?= format_money($booking->rate_applied) ?> / night</span>
                </div>
                <hr>
                <div class="d-flex justify-content-between">
                    <span class="fw-semibold">Total</span>
                    <span class="fw-bold fs-5"><?= format_money($total) ?></span>
                </div>
                <?php if ($booking->notes): ?>
                    <hr>
                    <div class="text-muted small text-uppercase fw-bold mb-1">Notes</div>
                    <p class="small mb-0"><?= esc($booking->notes) ?></p>
                <?php endif; ?>
            </div>
            <div class="card-footer bg-white">
                <a href="<?= site_url('bookings/' . $booking->id) ?>" class="small text-decoration-none"><i class="bi bi-arrow-up-right me-1"></i>View Full Booking</a>
            </div>
        </div>
    </div>
</div>

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

<?= $this->section('styles') ?>
.info-box { background: color-mix(in srgb, var(--brand) 6%, white); border-radius: 8px; padding: 0.65rem 0.85rem; }
<?= $this->endSection() ?>
