<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Quiz Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
        }

        h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 14px;
        }

        th,
        td {
            border: 1px solid #000;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f0f0f0;
        }

        .badge {
            padding: 5px 10px;
            color: white;
            border-radius: 4px;
            font-weight: bold;
        }

        .status-passed {
            background-color: green;
        }

        .status-pending {
            background-color: orange;
        }

        .status-failed {
            background-color: red;
        }

        .status-other {
            background-color: gray;
        }
    </style>
</head>

<body>
    <h2>Quiz Report</h2>

    <table>
        <thead>
            <tr>
                <th>User</th>
                <th>Email</th>
                <th>Quiz level</th>
                <th>Status</th>
                <th>Score</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($data as $quiz)
                <tr>
                    <td>{{ $quiz->user->first_name ?? 'N/A' }}</td>
                    <td>{{ $quiz->user->email ?? 'N/A' }}</td>
                    <td>{{ $quiz->quiz->quiz_level ?? 'N/A' }}</td>
                    <td>
                        @php
                            $status = strtolower($quiz->status->value); // ✅ Use ->value to get string from Enum
                            $statusClass = match ($status) {
                                'passed' => 'status-passed',
                                'pending' => 'status-pending',
                                'failed' => 'status-failed',
                                default => 'status-other',
                            };
                        @endphp
                        <span class="badge {{ $statusClass }}">{{ ucfirst($quiz->status->label()) }}</span>
                    </td>
                    <td>{{ $quiz->score }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>
</body>

</html>
