<?php

require_once __DIR__ . '/functions.php';

$pdo = app_db_pdo();
$token = trim((string)($_GET['token'] ?? ''));
$result = $token !== ''
    ? saas_verify_email_token($pdo, $token)
    : ['ok' => false, 'errors' => ['Der Link ist ungueltig oder abgelaufen.']];

include 'header.php';
include 'headerline.php';
include 'nav.php';
?>

<section id="banner">
    <div class="content">
        <h2>E-Mail verifizieren</h2>

        <?php if ($result['ok']): ?>
            <div class="hint-box success"><p>Die E-Mail-Adresse wurde bestaetigt.</p></div>
            <ul class="actions">
                <li><a href="konto.php" class="button">Zum Konto</a></li>
            </ul>
        <?php else: ?>
            <div class="hint-box error">
                <?php foreach ($result['errors'] as $error): ?>
                    <p><?php echo saas_html($error); ?></p>
                <?php endforeach; ?>
            </div>
            <ul class="actions">
                <li><a href="login.php" class="button">Zum Login</a></li>
            </ul>
        <?php endif; ?>
    </div>
</section>

<?php include 'footer.php'; ?>
