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

<head>
    <meta charset="UTF-8">
    <title>Contest Participants 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>Contest Participants Report</h2>

    <table>
        <thead>
            <tr>
                <th>User</th>
                <th>Email</th>
                <th>Contest</th>
                <th>Prize</th>
                <th>Score</th>
                <th>Time Taken</th>
                <th>Submitted At</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($data as $participant)
                <tr>
                    <td>{{ $participant->user->first_name ?? 'N/A' }}</td>
                    <td>{{ $participant->user->email ?? 'N/A' }}</td>
                    <td>{{ $participant->contest->name ?? 'N/A' }}</td>
                    <td>{{ $participant->prize->name ?? 'None' }}</td>
                    <td>{{ $participant->score }}</td>
                    <td>{{ $participant->time_taken ?? '-' }}</td>
                    <td>{{ $participant->submitted_at ? $participant->submitted_at->format('Y-m-d H:i') : 'Not Submitted' }}
                    </td>
                    <td>
                        @php
                            $status = strtolower($participant->status->value ?? 'other');
                            $statusClass = match ($status) {
                                'passed' => 'status-passed',
                                'pending' => 'status-pending',
                                'failed' => 'status-failed',
                                default => 'status-other',
                            };
                        @endphp
                        <span
                            class="badge {{ $statusClass }}">{{ ucfirst($participant->status->label() ?? $status) }}</span>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</body>

</html>
