<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Enable two-factor · Epelcon Hospitality</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <script src="https://cdn.tailwindcss.com?plugins=forms"></script>
    <script>tailwind.config = { theme: { extend: { fontFamily: { sans: ['"Plus Jakarta Sans"', 'sans-serif'], serif: ['"Playfair Display"', 'serif'] }, colors: { gold: { 400: '#d4af37', 500: '#c9a227', 600: '#a8871f' } } } } };</script>
</head>
<body class="min-h-screen bg-slate-950 font-sans text-slate-800 antialiased">
<div class="absolute inset-0 opacity-30" style="background-image: radial-gradient(circle at 15% 15%, #c9a22740 0, transparent 40%), radial-gradient(circle at 85% 80%, #4f46e540 0, transparent 40%)"></div>

<div class="relative flex min-h-screen items-center justify-center p-4">
    <div class="w-full max-w-lg">
        <a href="{{ route('home') }}" class="mb-8 flex flex-col items-center gap-2">
            <div class="flex h-14 w-14 items-center justify-center rounded-2xl bg-gradient-to-br from-gold-400 to-gold-600 text-2xl font-extrabold text-slate-950 shadow-xl shadow-gold-500/20">E</div>
            <span class="font-serif text-2xl font-bold text-white">Epelcon Hospitality</span>
            <span class="text-[10px] font-bold uppercase tracking-[0.35em] text-gold-400">Two-factor setup</span>
        </a>

        <div class="rounded-3xl bg-white p-7 shadow-2xl sm:p-9">
            <h1 class="text-xl font-extrabold text-slate-900">Enable two-factor authentication</h1>
            <p class="mt-1 text-sm text-slate-500">Scan the QR code with Google Authenticator, Authy or 1Password, then enter the 6-digit code to confirm.</p>

            @if (session('success'))
                <div class="mt-4 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">{{ session('success') }}</div>
            @endif
            @if ($errors->any())
                <div class="mt-4 rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-800">{{ $errors->first() }}</div>
            @endif

            <div class="mt-6 flex flex-col items-center gap-4 rounded-2xl bg-slate-50 p-6 ring-1 ring-slate-200">
                <div id="qr-target" data-url="{{ $otpauth }}" class="rounded-xl bg-white p-3 ring-1 ring-slate-200"></div>
                <div class="w-full">
                    <p class="text-[10px] font-bold uppercase tracking-[0.25em] text-slate-500">Manual entry code</p>
                    <p class="mt-1 select-all break-all font-mono text-sm font-bold text-slate-900">{{ $secret }}</p>
                </div>
            </div>

            <form method="POST" action="{{ route('2fa.confirm') }}" class="mt-6 space-y-4">
                @csrf
                <label class="block">
                    <span class="mb-1 block text-xs font-bold uppercase tracking-wide text-slate-500">6-digit code</span>
                    <input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="6" name="code" required autofocus autocomplete="one-time-code" class="w-full rounded-xl border-slate-200 text-center font-mono text-2xl tracking-[0.5em] focus:border-gold-500 focus:ring-gold-500">
                </label>
                <button class="w-full rounded-xl bg-slate-950 py-3.5 text-sm font-extrabold text-white shadow-lg hover:bg-slate-800">Confirm & enable</button>
            </form>

            <p class="mt-5 text-center text-sm text-slate-500">
                <a href="{{ route('epelcon.settings.index', [], false) ?: url('/') }}" class="font-bold text-gold-600 hover:underline">Cancel and go back</a>
            </p>
        </div>
        <p class="mt-6 text-center text-xs text-slate-500">© {{ date('Y') }} Epelcon Hospitality</p>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script>
    (function () {
        var el = document.getElementById('qr-target');
        if (!el) return;
        new QRCode(el, {
            text: el.dataset.url,
            width: 180,
            height: 180,
            correctLevel: QRCode.CorrectLevel.M,
        });
    })();
</script>
</body>
</html>
