{{define "2fa_setup.html"}}
<!DOCTYPE html>
<html lang="fr" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Activer 2FA - SOGOMS Admin</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
    <style>
        .container {
            max-width: 600px;
            margin: 2rem auto;
            padding: 0 1rem;
        }
        .logo {
            text-align: center;
            font-size: 1.5rem;
            font-weight: bold;
            margin-bottom: 2rem;
        }
        .logo span {
            color: var(--pico-primary);
        }
        .error-message {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: #dc2626;
            padding: 0.75rem 1rem;
            border-radius: var(--pico-border-radius);
            margin-bottom: 1rem;
        }
        .success-message {
            background: #f0fdf4;
            border: 1px solid #bbf7d0;
            color: #16a34a;
            padding: 0.75rem 1rem;
            border-radius: var(--pico-border-radius);
            margin-bottom: 1rem;
        }
        .qr-container {
            text-align: center;
            margin: 2rem 0;
            padding: 1rem;
            background: white;
            border-radius: var(--pico-border-radius);
        }
        .qr-container img {
            max-width: 200px;
        }
        .secret-code {
            font-family: monospace;
            font-size: 1.1rem;
            background: var(--pico-form-element-background-color);
            padding: 0.5rem 1rem;
            border-radius: var(--pico-border-radius);
            word-break: break-all;
        }
        .backup-codes {
            font-family: monospace;
            font-size: 0.95rem;
            background: var(--pico-form-element-background-color);
            padding: 1rem;
            border-radius: var(--pico-border-radius);
            white-space: pre-wrap;
            line-height: 1.8;
        }
        .warning {
            background: #fffbeb;
            border: 1px solid #fde68a;
            color: #92400e;
            padding: 0.75rem 1rem;
            border-radius: var(--pico-border-radius);
            margin: 1rem 0;
            font-size: 0.9rem;
        }
        .step {
            margin-bottom: 2rem;
        }
        .step h3 {
            margin-bottom: 1rem;
        }
        .code-input {
            text-align: center;
            font-size: 1.5rem;
            letter-spacing: 0.5rem;
            font-family: monospace;
            max-width: 200px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">SOGO<span>MS</span> Admin</div>

        <h1>Activer l'authentification à deux facteurs</h1>

        {{if .Error}}
        <div class="error-message">{{.Error}}</div>
        {{end}}

        <div class="step">
            <h3>Étape 1 : Scanner le QR Code</h3>
            <p>Scannez ce code avec votre application d'authentification (Google Authenticator, Authy, Microsoft Authenticator...).</p>

            <div class="qr-container">
                {{if .QRCodeDataURL}}
                <img src="{{.QRCodeDataURL | safeURL}}" alt="QR Code pour 2FA">
                {{end}}
            </div>

            <details>
                <summary>Ou entrez le secret manuellement</summary>
                <p style="margin-top: 1rem;">
                    <code class="secret-code">{{.TwoFASecret}}</code>
                </p>
            </details>
        </div>

        <div class="step">
            <h3>Étape 2 : Sauvegardez vos codes de secours</h3>
            <div class="warning">
                Conservez ces codes dans un endroit sûr. Chaque code ne peut être utilisé qu'une seule fois en cas de perte de votre téléphone.
            </div>
            <div class="backup-codes">{{.BackupCodesFormatted}}</div>
        </div>

        <div class="step">
            <h3>Étape 3 : Vérifier le code</h3>
            <p>Entrez le code à 6 chiffres affiché dans votre application pour confirmer l'activation.</p>

            <form action="/admin/2fa/setup" method="post">
                <input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
                <input type="hidden" name="temp_secret" value="{{.TwoFASecret}}">
                <input type="hidden" name="backup_codes" value="{{range $i, $code := .BackupCodes}}{{if $i}},{{end}}{{$code}}{{end}}">

                <label for="verify_code">
                    Code d'authentification
                    <input type="text" id="verify_code" name="verify_code" class="code-input"
                           inputmode="numeric" maxlength="6" pattern="[0-9]{6}"
                           placeholder="000000" required autofocus
                           autocomplete="one-time-code">
                </label>

                <button type="submit">Vérifier et activer le 2FA</button>
            </form>
        </div>

        <footer style="text-align: center; margin-top: 2rem;">
            <a href="/admin/" style="font-size: 0.9rem;">Annuler</a>
        </footer>
    </div>
</body>
</html>
{{end}}
