<?php
declare(strict_types=1);

require_once __DIR__ . '/app/Helpers/bootstrap.php';

$type = (string)($_GET['type'] ?? '');
$key = $type === 'privacy' ? 'privacy_text' : ($type === 'legal' ? 'legal_text' : '');
if ($key === '') { http_response_code(404); exit('Not found.'); }

$query = db()->prepare('SELECT setting_value FROM ' . table('settings') . ' WHERE setting_key = :key');
$query->execute([':key' => $key]);
$text = (string)$query->fetchColumn();
if ($text === '') { http_response_code(404); exit('Not found.'); }

$titleKey = $type === 'privacy' ? 'footer.privacy' : 'footer.legal';
$title = t($titleKey);
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></title>
    <style>
        body{font-family:system-ui;background:#f4f6f8;margin:0;padding:32px}
        main{max-width:760px;margin:auto;background:#fff;padding:28px;border-radius:14px}
        .button{display:inline-block;padding:10px 13px;background:#126e82;color:#fff;border:0;border-radius:7px;text-decoration:none;font:inherit;font-weight:700;cursor:pointer}
        .back{background:#e3ebee;color:#126e82;margin:0 0 12px}
        @media(max-width:600px){body{padding:12px}main{padding:18px}.back{display:inline-block;width:auto;max-width:100%;text-align:left}}
    </style>
</head>
<body>
<main>
    <a class="button back" href="/dashboard.php"><?= htmlspecialchars(t('legal.back'), ENT_QUOTES, 'UTF-8') ?></a>
    <h1><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></h1>
    <?= render_rich_text($text) ?>
</main>
</body>
</html>
