<?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>

    <div class="public-card">
        <h1 class="h5 mb-1">Set Your Password</h1>
        <p class="text-muted small mb-3">Enter the code we texted you, along with the email and a new password.</p>

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

        <form action="<?= site_url('organizer/set-password') ?>" method="post">
            <?= csrf_field() ?>
            <div class="mb-3">
                <label class="form-label small fw-semibold">Email</label>
                <input type="email" class="form-control" name="email" value="<?= esc(old('email') ?: ($email ?? '')) ?>" required>
            </div>
            <div class="mb-3">
                <label class="form-label small fw-semibold">Code</label>
                <input type="text" class="form-control" name="code" inputmode="numeric" maxlength="6" placeholder="6-digit code" required autofocus>
            </div>
            <div class="mb-3">
                <label class="form-label small fw-semibold">New Password</label>
                <input type="password" class="form-control" name="password" minlength="8" required>
            </div>
            <div class="mb-4">
                <label class="form-label small fw-semibold">Confirm Password</label>
                <input type="password" class="form-control" name="password_confirm" minlength="8" required>
            </div>
            <button type="submit" class="btn btn-brand w-100"><i class="bi bi-check2 me-1"></i>Set Password</button>
        </form>

        <form action="<?= site_url('organizer/set-password/resend') ?>" method="post" class="mt-3">
            <?= csrf_field() ?>
            <input type="hidden" name="email" value="<?= esc($email ?? '') ?>">
            <button type="submit" class="btn btn-link btn-sm w-100">Didn't get a code? Resend</button>
        </form>
    </div>
</div>
</body>
</html>
