                                                @foreach($certificates as $index => $certificate)
                                                    @php
                                                        $ctype = $certificate->certificate_type ?? 'old';
                                                        $downloadUrl = certificateDownloadUrl($certificate);
                                                    @endphp
                                                    <tr>
                                                        <td>{{ $index + 1 }}</td>
                                                        <td>
                                                            @if($ctype === 'old')
                                                                @if($certificate->type === 'quiz')
                                                                    <span class="badge badge-primary">{{ trans('quiz.certificate_kind_quiz') }}</span>
                                                                @elseif($certificate->type === 'course')
                                                                    <span class="badge badge-success">{{ trans('quiz.certificate_kind_course') }}</span>
                                                                @elseif($certificate->type === 'imtmontessori')
                                                                    <span class="badge badge-warning">{{ trans('quiz.certificate_kind_montessori') }}</span>
                                                                @else
                                                                    <span class="badge badge-secondary">{{ $certificate->type }}</span>
                                                                @endif
                                                            @elseif($ctype === 'new')
                                                                <span class="badge badge-info">{{ trans('quiz.certificate_kind_template') }}</span>
                                                            @elseif($ctype === 'last')
                                                                <span class="badge badge-dark">{{ trans('quiz.certificate_kind_generated') }}</span>
                                                            @endif
                                                        </td>
                                                        <td>
                                                            @if($ctype === 'old')
                                                                @if($certificate->type === 'quiz' && !empty($certificate->quiz))
                                                                    {{ $certificate->quiz->webinar ? $certificate->quiz->webinar->title : $certificate->quiz->title }}
                                                                @elseif($certificate->webinar)
                                                                    {{ $certificate->webinar->title }}
                                                                @else
                                                                    <span class="text-muted">—</span>
                                                                @endif
                                                            @elseif($ctype === 'new')
                                                                {{ $certificate->course_name ?? optional($certificate->template)->title ?? '—' }}
                                                            @elseif($ctype === 'last')
                                                                {{ $certificate->template_name ?? trans('quiz.certificate_kind_generated') }}
                                                            @endif
                                                        </td>
                                                        <td>
                                                            @if($ctype === 'old')
                                                                @if(!empty($certificate->user_grade))
                                                                    {{ $certificate->user_grade }}%
                                                                @elseif(!empty($certificate->serial_number))
                                                                    {{ $certificate->serial_number }}
                                                                @else
                                                                    <span class="text-muted">—</span>
                                                                @endif
                                                            @elseif($ctype === 'new')
                                                                {{ $certificate->serial_number ?? '—' }}
                                                            @else
                                                                <span class="text-muted">—</span>
                                                            @endif
                                                        </td>
                                                        <td>
                                                            @if($ctype === 'old')
                                                                {{ dateTimeFormat($certificate->created_at, 'j M Y') }}
                                                            @elseif($ctype === 'new' && !empty($certificate->completion_date))
                                                                {{ $certificate->completion_date instanceof \Carbon\Carbon ? dateTimeFormat($certificate->completion_date->timestamp, 'j M Y') : dateTimeFormat(strtotime((string) $certificate->completion_date), 'j M Y') }}
                                                            @elseif($ctype === 'last' && !empty($certificate->generated_at))
                                                                {{ dateTimeFormat($certificate->generated_at instanceof \Carbon\Carbon ? $certificate->generated_at->timestamp : strtotime((string) $certificate->generated_at), 'j M Y') }}
                                                            @else
                                                                <span class="text-muted">—</span>
                                                            @endif
                                                        </td>
                                                        <td>
                                                            @if(!empty($downloadUrl))
                                                                <a href="{{ $downloadUrl }}" target="_blank" class="btn btn-sm btn-primary">
                                                                    <i class="fas fa-download"></i> {{ trans('quiz.certificate_download') }}
                                                                </a>
                                                            @else
                                                                <span class="text-muted font-12">{{ trans('quiz.certificate_pending_file') }}</span>
                                                            @endif
                                                        </td>
                                                    </tr>
                                                @endforeach
