<?php
// Simple debug script to show available quizzes
require __DIR__.'/../vendor/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

echo "<html><head><title>Available Quizzes</title></head><body>";
echo "<h1>Available Quizzes in Database</h1>";
echo "<style>table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid black; padding: 8px; text-align: left; } th { background: #f2f2f2; }</style>";

try {
    $quizzes = DB::table('quizzes')
        ->select('id', 'title', 'slug', 'category_id', 'start_date', 'end_date')
        ->orderBy('id', 'desc')
        ->limit(50)
        ->get();
    
    echo "<table>";
    echo "<tr><th>ID</th><th>Title</th><th>Slug</th><th>Category ID</th><th>Start Date</th><th>End Date</th><th>Student Link</th></tr>";
    
    foreach ($quizzes as $quiz) {
        $studentLink = "http://localhost/testapp/exams/student/start-exam/{$quiz->slug}";
        echo "<tr>";
        echo "<td>{$quiz->id}</td>";
        echo "<td>{$quiz->title}</td>";
        echo "<td><strong>{$quiz->slug}</strong></td>";
        echo "<td>{$quiz->category_id}</td>";
        echo "<td>{$quiz->start_date}</td>";
        echo "<td>{$quiz->end_date}</td>";
        echo "<td><a href='{$studentLink}' target='_blank'>Test Link</a></td>";
        echo "</tr>";
    }
    
    echo "</table>";
    echo "<p><strong>Total Quizzes Found:</strong> " . count($quizzes) . "</p>";
    
} catch (Exception $e) {
    echo "<p style='color: red;'><strong>Error:</strong> " . $e->getMessage() . "</p>";
}

echo "</body></html>";