@extends('layouts.student')

@section('title', 'My Results')

@section('content')
<div class="container mt-4">
    <div class="card shadow-sm">
        <div class="card-header bg-success text-white">
            <h5 class="mb-0">My Academic Results</h5>
        </div>
        <div class="card-body">
            @if ($groups->isEmpty())
                <p class="text-muted">No results available yet.</p>
            @else
                @foreach ($groups as $groupLabel => $records)
                    <h5 class="mt-4 text-primary">{{ $groupLabel }}</h5>
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead class="table-dark">
                                <tr>
                                    <th>Course Code</th>
                                    <th>Course Description</th>
                                    <th>Grade</th>
                                    <th>Decision</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($records as $row)
                                    <tr>
                                        <td>{{ $row->course_code }}</td>
                                        <td>{{ $row->course_description }}</td>
                                        <td>{{ $row->grade }}</td>
                                        <td>
                                            @php
                                                $finalMark = $row->final_mark;
                                                if ($finalMark >= 50) {
                                                    $decisionLetter = 'P';
                                                    $badgeClass = 'bg-success text-warning fw-bold';
                                                } elseif ($finalMark >= 40) {
                                                    $decisionLetter = 'S';
                                                    $badgeClass = 'bg-warning text-dark fw-bold';
                                                } else {
                                                    $decisionLetter = 'F';
                                                    $badgeClass = 'bg-danger text-white fw-bold';
                                                }
                                            @endphp
                                            <span class="badge px-3 py-2 {{ $badgeClass }}" style="border-radius: 0.35rem;">
                                                {{ $decisionLetter }}
                                            </span>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @endforeach
            @endif
        </div>
    </div>
</div>
@endsection
