<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Recovery codes · 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 print:hidden" 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 print:hidden">
            <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">Recovery codes</span>
        </a>

        <div class="rounded-3xl bg-white p-7 shadow-2xl sm:p-9">
            <h1 class="text-xl font-extrabold text-slate-900">Your recovery codes</h1>
            <p class="mt-1 text-sm text-slate-500">Store these somewhere safe. Each code can be used once if you lose access to your authenticator app.</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

            @if (! empty($codes))
                <div id="recovery-codes" class="mt-6 grid grid-cols-2 gap-2 rounded-2xl bg-slate-50 p-5 font-mono text-sm ring-1 ring-slate-200">
                    @foreach ($codes as $code)
                        <div class="rounded-lg bg-white px-3 py-2 text-center font-bold text-slate-900 ring-1 ring-slate-200">{{ $code }}</div>
                    @endforeach
                </div>

                <div class="mt-4 flex flex-wrap gap-2 print:hidden">
                    <button type="button" onclick="copyCodes()" class="flex-1 rounded-xl bg-slate-900 py-2.5 text-sm font-bold text-white hover:bg-slate-700">Copy codes</button>
                    <button type="button" onclick="window.print()" class="flex-1 rounded-xl bg-white py-2.5 text-sm font-bold text-slate-900 ring-1 ring-slate-300 hover:bg-slate-50">Print</button>
                </div>
                <p class="mt-4 text-center text-xs text-slate-500">These codes will not be shown again after you leave this page.</p>
            @else
                <div class="mt-6 rounded-2xl bg-slate-50 p-6 ring-1 ring-slate-200 text-sm text-slate-600">
                    Recovery codes are only shown once. If you've lost them, regenerate a new set below — the old codes will stop working immediately.
                </div>
            @endif

            <form method="POST" action="{{ route('2fa.recovery.regenerate') }}" class="mt-6 space-y-3 rounded-2xl border border-slate-200 p-5 print:hidden">
                @csrf
                <p class="text-sm font-bold text-slate-900">Regenerate recovery codes</p>
                <label class="block">
                    <span class="mb-1 block text-xs font-bold uppercase tracking-wide text-slate-500">Confirm password</span>
                    <input type="password" name="password" required autocomplete="current-password" class="w-full rounded-xl border-slate-200 text-sm focus:border-gold-500 focus:ring-gold-500">
                </label>
                <button class="w-full rounded-xl bg-slate-950 py-3 text-sm font-extrabold text-white hover:bg-slate-800">Generate new codes</button>
            </form>

            <p class="mt-5 text-center text-sm text-slate-500 print:hidden">
                <a href="{{ url('/') }}" class="font-bold text-gold-600 hover:underline">Done</a>
            </p>
        </div>
        <p class="mt-6 text-center text-xs text-slate-500 print:hidden">© {{ date('Y') }} Epelcon Hospitality</p>
    </div>
</div>

<script>
    function copyCodes() {
        var el = document.getElementById('recovery-codes');
        if (!el) return;
        var text = Array.from(el.querySelectorAll('div')).map(function (d) { return d.textContent.trim(); }).join('\n');
        navigator.clipboard.writeText(text).then(function () {
            alert('Recovery codes copied to clipboard.');
        });
    }
</script>
</body>
</html>
