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

@section('content')
    <div class="card"><div class="card-body">
        <table class="table table-hover align-middle">
            <thead><tr><th>Session</th><th>Start</th><th>End</th><th class="text-center">Students</th><th class="text-center">Current</th><th class="text-end">Actions</th></tr></thead>
            <tbody>
                @foreach($sessions as $s)
                    <tr>
                        <td class="fw-semibold">{{ $s->name }}</td>
                        <td>{{ optional($s->start_date)->format('d M Y') ?? '—' }}</td>
                        <td>{{ optional($s->end_date)->format('d M Y') ?? '—' }}</td>
                        <td class="text-center">{{ $s->students_count }}</td>
                        <td class="text-center">@if($s->is_current)<span class="badge bg-soft-success">Current</span>@else<span class="text-muted">—</span>@endif</td>
                        <td class="text-end">
                            @can('academics.update')<a href="{{ route('sessions.edit', $s) }}" class="btn btn-sm btn-light border"><i class="bi bi-pencil"></i></a>@endcan
                            @can('academics.delete')
                                <form method="POST" action="{{ route('sessions.destroy', $s) }}" class="d-inline" data-confirm="Delete session {{ $s->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>
                @endforeach
            </tbody>
        </table>
    </div></div>
@endsection
