<?php
// Sanitize for display
$examContent = htmlspecialchars($responseText);
$isError = strpos($responseText, 'ERROR:') === 0;

$schoolName = $_SESSION['last_meta']['school_name'] ?? '';
$session = ($_SESSION['last_meta']['exam_year'] ?? date('Y')) . ' ACADEMIC SESSION EXAMINATION';

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Generated Exam</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="main-container">
        <div class="exam-card">
            <div class="card-header">
                <h1>Your Generated Exam</h1>
                <?php if (!$isError): ?>
                <p>Review the generated exam below or download it in your preferred format.</p>
                <?php else: ?>
                <p style="color: #d9534f;">An error occurred during generation.</p>
                <?php endif; ?>
            </div>

            <?php if (!$isError && $schoolName): ?>
            <div style="text-align: center; font-weight: bold; margin-bottom: 1rem; text-transform: uppercase;">
                <div style="font-size: 1.5rem;"><?= htmlspecialchars($schoolName) ?></div>
                <div style="font-size: 1.2rem;"><?= htmlspecialchars($session) ?></div>
            </div>
            <?php endif; ?>

            <pre><?= $examContent ?></pre>

            <div class="action-buttons">
                <a href="/" class="btn-back">Go Back</a>
                <?php if (!$isError): ?>
                <a href="#" onclick="window.print(); return false;" class="btn-print">Print</a>
                <a href="/download/pdf" class="btn-pdf">Download PDF</a>
                <a href="/download/docx" class="btn-docx">Download DOCX</a>
                <?php endif; ?>
            </div>
        </div>
        <div class="footer">
            Developed by Polycarp Ukadilonu (cpcodes web)
        </div>
    </div>
</body>
</html>