@extends('layouts.app')
@section('title', 'Exams')
@section('page_title', 'Examinations')
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li><li class="breadcrumb-item active">Exams</li>
@endsection
@section('page_actions')
    @can('exams.create')<a href="{{ route('exams.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>Add Exam</a>@endcan
@endsection

@section('content')
    <div class="card"><div class="card-body">
        <table class="table table-hover align-middle">
            <thead><tr><th>Exam</th><th>Type</th><th>Session</th><th>Dates</th><th class="text-center">Papers</th><th class="text-center">Marks</th><th class="text-center">Published</th><th class="text-end">Actions</th></tr></thead>
            <tbody>
                @forelse($exams as $exam)
                    <tr>
                        <td><a href="{{ route('exams.show', $exam) }}" class="fw-semibold text-decoration-none">{{ $exam->name }}</a></td>
                        <td><span class="badge bg-soft-info">{{ $exam->type_label }}</span></td>
                        <td class="small">{{ $exam->academicSession?->name ?? '—' }}</td>
                        <td class="small">{{ optional($exam->start_date)->format('d M') }} – {{ optional($exam->end_date)->format('d M Y') }}</td>
                        <td class="text-center">{{ $exam->papers_count }}</td>
                        <td class="text-center">{{ $exam->marks_count }}</td>
                        <td class="text-center">
                            @can('exams.update')
                                <form method="POST" action="{{ route('exams.publish', $exam) }}" class="d-inline">@csrf
                                    <button class="btn btn-sm {{ $exam->is_published ? 'btn-success' : 'btn-light border' }} py-0">
                                        <i class="bi bi-{{ $exam->is_published ? 'check-circle' : 'circle' }}"></i> {{ $exam->is_published ? 'Published' : 'Draft' }}
                                    </button>
                                </form>
                            @else
                                <span class="badge bg-soft-{{ $exam->is_published ? 'success' : 'secondary' }}">{{ $exam->is_published ? 'Published' : 'Draft' }}</span>
                            @endcan
                        </td>
                        <td class="text-end">
                            <a href="{{ route('exams.show', $exam) }}" class="btn btn-sm btn-light border"><i class="bi bi-gear"></i></a>
                            @can('exams.update')<a href="{{ route('exams.edit', $exam) }}" class="btn btn-sm btn-light border"><i class="bi bi-pencil"></i></a>@endcan
                            @can('exams.delete')<form method="POST" action="{{ route('exams.destroy', $exam) }}" class="d-inline" data-confirm="Delete {{ $exam->name }}?">@csrf @method('DELETE')<button class="btn btn-sm btn-light border text-danger"><i class="bi bi-trash"></i></button></form>@endcan
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="8" class="text-center text-muted py-4">No exams yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div></div>
@endsection
