<?php
$tenant = service('tenantContext')->hasTenant() ? service('tenantContext')->getTenant() : null;
$primaryColor   = safe_hex_color($tenant->primary_color ?? null, '#4f46e5');
$secondaryColor = safe_hex_color($tenant->secondary_color ?? null, '#f59e0b');
$hotelName      = $tenant->hotel_name ?? 'MaxYields PMS';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include APPPATH . 'Views/public/_shell_head.php'; ?>
</head>
<body>
<div class="public-shell">
    <div class="d-flex align-items-center gap-2 mb-4">
        <div class="brand-mark"><i class="bi bi-buildings-fill"></i></div>
        <div class="brand-name"><?= esc($hotelName) ?></div>
    </div>

    <?php if (session()->getFlashdata('error')): ?>
        <div class="alert alert-danger py-2 small"><?= esc(session()->getFlashdata('error')) ?></div>
    <?php endif; ?>
    <?php if (isset($validation)): ?>
        <div class="alert alert-danger py-2 small"><?= $validation->listErrors() ?></div>
    <?php endif; ?>

    <div class="public-card mb-3">
        <h1 class="h6 mb-2"><?= esc($roomType->name) ?></h1>
        <div class="d-flex justify-content-between text-muted small mb-1">
            <span><?= esc(date('d M Y', strtotime($checkIn))) ?> &rarr; <?= esc(date('d M Y', strtotime($checkOut))) ?></span>
            <span><?= $nights ?> night<?= $nights === 1 ? '' : 's' ?></span>
        </div>
        <div class="d-flex justify-content-between small"><span>Room total</span><span><?= format_money($roomTotal) ?></span></div>
        <div class="d-flex justify-content-between fw-semibold border-top mt-2 pt-2">
            <span>Deposit due now (<?= $depositPercent ?>%)</span>
            <span><?= format_money($depositAmount) ?></span>
        </div>
    </div>

    <div class="public-card">
        <h2 class="h6 mb-3">Your Details</h2>
        <form action="<?= site_url('widget/booking/confirm') ?>" method="post">
            <input type="hidden" name="room_type_id" value="<?= (int) $roomType->id ?>">
            <input type="hidden" name="check_in" value="<?= esc($checkIn) ?>">
            <input type="hidden" name="check_out" value="<?= esc($checkOut) ?>">

            <div class="mb-3">
                <label class="form-label small fw-semibold">Full Name</label>
                <input type="text" class="form-control" name="full_name" value="<?= esc(old('full_name')) ?>" required>
            </div>
            <div class="mb-3">
                <label class="form-label small fw-semibold">Phone</label>
                <input type="tel" class="form-control" name="phone" placeholder="024XXXXXXX" value="<?= esc(old('phone')) ?>" required>
            </div>
            <div class="mb-3">
                <label class="form-label small fw-semibold">Email <span class="text-muted fw-normal">(optional)</span></label>
                <input type="email" class="form-control" name="email" value="<?= esc(old('email')) ?>">
            </div>
            <div class="row g-2 mb-4">
                <div class="col-6">
                    <label class="form-label small fw-semibold">Adults</label>
                    <input type="number" class="form-control" name="adults" min="1" value="1">
                </div>
                <div class="col-6">
                    <label class="form-label small fw-semibold">Children</label>
                    <input type="number" class="form-control" name="children" min="0" value="0">
                </div>
            </div>

            <button type="submit" class="btn btn-brand w-100"><i class="bi bi-credit-card me-1"></i>Pay Deposit &amp; Confirm</button>
            <p class="text-muted small text-center mt-2 mb-0">You'll be taken to a secure Hubtel payment page.</p>
        </form>
    </div>
</div>
</body>
</html>
