<?php
require_once __DIR__ . '/../src/bootstrap.php';
require_once __DIR__ . '/../src/functions.php';

$pdo = db();
$token = trim($_GET['token'] ?? '');

$success = false;
$message = 'Geçersiz abonelikten çıkış bağlantısı.';

if ($token !== '') {
    try {
        $success = unsubscribeByToken($pdo, $token);
        $message = $success ? 'E-posta listesinden başarıyla çıkarıldınız.' : 'Bu bağlantı geçersiz ya da daha önce kullanılmış olabilir.';
    } catch (\Throwable $e) {
        $message = 'Bir hata oluştu: ' . $e->getMessage();
    }
}
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Abonelikten Çık</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; font-family: Arial, Helvetica, sans-serif; background: #f5f7fb; color: #111827; padding: 20px; }
.card { width: 100%; max-width: 560px; background: #fff; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); padding: 32px 24px; text-align: center; }
.icon { width: 72px; height: 72px; border-radius: 999px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; }
.icon.success { background: #dcfce7; color: #166534; }
.icon.error { background: #fee2e2; color: #991b1b; }
h1 { margin: 0 0 12px; font-size: 28px; }
p { margin: 0; font-size: 16px; line-height: 1.6; color: #4b5563; }
.btn { display: inline-flex; margin-top: 24px; text-decoration: none; background: #2563eb; color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; }
</style>
</head>
<body>
<div class="card">
    <div class="icon <?= $success ? 'success' : 'error' ?>"><?= $success ? '✓' : '!' ?></div>
    <h1><?= $success ? 'İşlem Tamamlandı' : 'İşlem Başarısız' ?></h1>
    <p><?= e($message) ?></p>
    <a class="btn" href="index.php">Panele Dön</a>
</div>
</body>
</html>
