@extends('layouts.app')
@section('title', 'My Results')
@section('page-title', 'My Results')
@section('sidebar-nav')
<div class="nav-item"><a href="{{ route('student.dashboard') }}"><i class="bi bi-grid"></i> Dashboard</a></div>
<div class="nav-item"><a href="{{ route('student.results') }}"><i class="bi bi-bar-chart"></i> My Results</a></div>
<div class="nav-item"><a href="{{ route('student.fees') }}"><i class="bi bi-cash"></i> Fee Balance</a></div>
<div class="nav-item"><a href="{{ route('student.attendance') }}"><i class="bi bi-calendar-check"></i> Attendance</a></div>
<div class="nav-item"><a href="{{ route('student.assignments') }}"><i class="bi bi-file-earmark-text"></i> Assignments</a></div>
@endsection

@section('content')
<div class="page-header"><div><h1>My Results</h1></div></div>

@forelse($exams as $exam)
<div class="card" style="margin-bottom:20px;">
    <div class="card-header">
        <h5>{{ $exam->name }} &mdash; {{ $exam->term->name }}</h5>
        @php
            $totalPoints = $exam->marks->sum('points');
            $count = $exam->marks->count();
            $mean = $count > 0 ? round($totalPoints / $count, 1) : 0;
        @endphp
        <span class="badge badge-success">Mean: {{ $mean }} pts</span>
    </div>
    <div class="table-wrap">
        <table>
            <thead><tr><th>Subject</th><th>Score</th><th>Grade</th><th>Points</th><th>Remarks</th></tr></thead>
            <tbody>
                @foreach($exam->marks as $mark)
                <tr>
                    <td>{{ $mark->subject->name }}</td>
                    <td>{{ $mark->score }}/{{ $mark->out_of }}</td>
                    <td><span class="badge badge-info">{{ $mark->grade }}</span></td>
                    <td>{{ $mark->points }}</td>
                    <td>{{ $mark->remarks }}</td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@empty
<div class="card"><div class="card-body" style="text-align:center;padding:40px;color:var(--gray);">No published results yet</div></div>
@endforelse
@endsection
