<?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 ungültig oder abgelaufen.']];

?>

<!DOCTYPE HTML>
<html lang="de">
    <head>
        <title>Kaffeeliste E-Mail verifizieren</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <link rel="stylesheet" href="assets/css/main.css" />
        <link rel="stylesheet" href="assets/css/public.css" />
    </head>
    <body class="is-preload public-page">
        <div class="public-shell">
            <section class="public-auth">
                <nav class="public-nav" aria-label="Hauptnavigation">
                    <strong><a href="landing.php">Kaffeeliste</a></strong>
                    <ul class="actions">
                        <li><a href="login.php" class="button">Login</a></li>
                    </ul>
                </nav>

                <div class="public-auth-grid">
                    <div class="public-auth-copy">
                        <h1>E-Mail verifizieren</h1>
                        <p>Bestätige deine Adresse, damit dein Kundenkonto vollständig eingerichtet ist.</p>
                    </div>

                    <div class="public-panel">
                        <h2>Status</h2>

                        <?php if ($result['ok']): ?>
                            <div class="hint-box success"><p>Die E-Mail-Adresse wurde bestätigt.</p></div>
                            <ul class="actions">
                                <li><a href="konto.php" class="button primary">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 primary">Zum Login</a></li>
                            </ul>
                        <?php endif; ?>
                    </div>
                </div>
            </section>
        </div>

        <script src="assets/js/jquery.min.js"></script>
        <script src="assets/js/browser.min.js"></script>
        <script src="assets/js/breakpoints.min.js"></script>
        <script src="assets/js/util.js"></script>
        <script src="assets/js/main.js"></script>
    </body>
</html>
